Jquery scrollLeft not working second time
up vote
0
down vote
favorite
I have the below script which automatically scrolls right to slide the images. Unfortunately I'm not able to reset the counter. I've done a condition to see if the scroll is finished, and if it is then reset the width of the scroll, but it seems to not be working. However, if instead of reseting the scroll, I place an alert - then resetting the width works, but scrolling is still not working.
All is working good until the for loop ends and I'm not able to reset the scroll to the beginning.
Here is the script:
<script>
$(function ($) {
$('#headw').on('scroll', function () {
if($(this).scrollLeft() + $(this).innerWidth() >= $(this)[0].scrollWidth) {
// RESET THE COUNTER
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
else if($(this).scrollLeft() === 0) {
// Remove this part if you don't want your messages hidden again
}
else {
}
})
});
function doItAll() {
// put state variables other than the actual loop control here
function doTheLoop() {
var i;
var count;
var total = <?php echo $row; ?>;
var tx = total + 1;
for (i = 0; i < total; i++) {
var width = $(".divisorx").outerWidth();
count = count + width;
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
return(false); // done running the loop
}
while (doTheLoop()) {}
// do some things after the loop
}
doItAll();
</script>
javascript jquery
add a comment |
up vote
0
down vote
favorite
I have the below script which automatically scrolls right to slide the images. Unfortunately I'm not able to reset the counter. I've done a condition to see if the scroll is finished, and if it is then reset the width of the scroll, but it seems to not be working. However, if instead of reseting the scroll, I place an alert - then resetting the width works, but scrolling is still not working.
All is working good until the for loop ends and I'm not able to reset the scroll to the beginning.
Here is the script:
<script>
$(function ($) {
$('#headw').on('scroll', function () {
if($(this).scrollLeft() + $(this).innerWidth() >= $(this)[0].scrollWidth) {
// RESET THE COUNTER
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
else if($(this).scrollLeft() === 0) {
// Remove this part if you don't want your messages hidden again
}
else {
}
})
});
function doItAll() {
// put state variables other than the actual loop control here
function doTheLoop() {
var i;
var count;
var total = <?php echo $row; ?>;
var tx = total + 1;
for (i = 0; i < total; i++) {
var width = $(".divisorx").outerWidth();
count = count + width;
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
return(false); // done running the loop
}
while (doTheLoop()) {}
// do some things after the loop
}
doItAll();
</script>
javascript jquery
Possible duplicate of Jquery reset horizontal scroll is not working
– Marcelo Myara
Nov 19 at 23:30
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the below script which automatically scrolls right to slide the images. Unfortunately I'm not able to reset the counter. I've done a condition to see if the scroll is finished, and if it is then reset the width of the scroll, but it seems to not be working. However, if instead of reseting the scroll, I place an alert - then resetting the width works, but scrolling is still not working.
All is working good until the for loop ends and I'm not able to reset the scroll to the beginning.
Here is the script:
<script>
$(function ($) {
$('#headw').on('scroll', function () {
if($(this).scrollLeft() + $(this).innerWidth() >= $(this)[0].scrollWidth) {
// RESET THE COUNTER
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
else if($(this).scrollLeft() === 0) {
// Remove this part if you don't want your messages hidden again
}
else {
}
})
});
function doItAll() {
// put state variables other than the actual loop control here
function doTheLoop() {
var i;
var count;
var total = <?php echo $row; ?>;
var tx = total + 1;
for (i = 0; i < total; i++) {
var width = $(".divisorx").outerWidth();
count = count + width;
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
return(false); // done running the loop
}
while (doTheLoop()) {}
// do some things after the loop
}
doItAll();
</script>
javascript jquery
I have the below script which automatically scrolls right to slide the images. Unfortunately I'm not able to reset the counter. I've done a condition to see if the scroll is finished, and if it is then reset the width of the scroll, but it seems to not be working. However, if instead of reseting the scroll, I place an alert - then resetting the width works, but scrolling is still not working.
All is working good until the for loop ends and I'm not able to reset the scroll to the beginning.
Here is the script:
<script>
$(function ($) {
$('#headw').on('scroll', function () {
if($(this).scrollLeft() + $(this).innerWidth() >= $(this)[0].scrollWidth) {
// RESET THE COUNTER
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
else if($(this).scrollLeft() === 0) {
// Remove this part if you don't want your messages hidden again
}
else {
}
})
});
function doItAll() {
// put state variables other than the actual loop control here
function doTheLoop() {
var i;
var count;
var total = <?php echo $row; ?>;
var tx = total + 1;
for (i = 0; i < total; i++) {
var width = $(".divisorx").outerWidth();
count = count + width;
$("#headw").animate({
scrollLeft: "+="+width+"px",
}, 3000);
}
return(false); // done running the loop
}
while (doTheLoop()) {}
// do some things after the loop
}
doItAll();
</script>
javascript jquery
javascript jquery
asked Nov 19 at 23:21
Goncalo
113
113
Possible duplicate of Jquery reset horizontal scroll is not working
– Marcelo Myara
Nov 19 at 23:30
add a comment |
Possible duplicate of Jquery reset horizontal scroll is not working
– Marcelo Myara
Nov 19 at 23:30
Possible duplicate of Jquery reset horizontal scroll is not working
– Marcelo Myara
Nov 19 at 23:30
Possible duplicate of Jquery reset horizontal scroll is not working
– Marcelo Myara
Nov 19 at 23:30
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384063%2fjquery-scrollleft-not-working-second-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Jquery reset horizontal scroll is not working
– Marcelo Myara
Nov 19 at 23:30