问题
jQuery v 1.7.2, Bootstrap v 2.0.4 (downloaded standard file from homepage this morning)
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script>$('#myCarousel').carousel({interval: false})</script>
I've seen lots of questions about this but according to the official Bootstrap blog (items 5 and 10 under the heading 'Javascript'), this issue was supposed to be resolved in v2.0.3.
I've added an interval false to the call, since this is supposed to (according to the docs) prevent it from sliding unless the user clicks the prev/next links.
At first this works fine: page loads, no sliding, user clicks next link, transitions nicely to the next slide. But if the user moves the mouse away from the container #myCarousel, then the sliding action starts automating again.
What's going on? I would really like the slide action to be under user control.
回答1:
I was unable to recreate the behavior that you described.
JS Fiddle
If you really are seeing this behavior you should report an issue on the Bootstrap repo.
That said, if you want to disable the hover-based pause toggling altogether, try using
$('#myCarousel').carousel({interval: 0, pause: 'none'});
That value for pause
just needs to be anything other than 'hover'
. The value for interval
just needs to be falsy, and I think using 0
makes more sense semantically, since it is supposed to be a Number otherwise.
Another option is manually switching off the mouse listeners:
$('#myCarousel').off('mouseenter').off('mouseleave');
来源:https://stackoverflow.com/questions/11325401/bootstrap-carousel-v2-0-4-restarts-on-mouseleave-event