How to handle a hide/show queue with multiple hidden divs smoothly

无人久伴 提交于 2020-01-05 18:55:41

问题


I've searched around, but nothing exactly like what I have.

When I scroll over the next div below or above the div with the show method it will just jumpToEnd of the current activity. I understand that .stop(true, true) is the reason it is doing this, but otherwise the divs will not appear in the right place on the page, going further to the left or stop display entirely after 2 or 3 events.

I'd like what ever currently shown divs to smoothly continue their hide behavior when I stop hovering or hover 1 of the other 2 divs. Then if I go back to them before they complete, reverse back to a show behavior. Cannot seem to get this going smoothly at least without .stop

Example: http://jsfiddle.net/JohnWeb/rBsLx/1/

This is my script so far:

$(document).ready(function(){
    $('#why-pic').hover(function(){
        $('#why-text').stop(true, true).show("slide", {easing:"easeInCirc"}, 1000);
    }, function(){
    $('#why-text').stop(true, true).hide("slide", {easing:"easeInCirc"}, 1000);
    });
    $('#what-pic').hover(function(){
        $('#what-text').stop(true, true).show("slide", {easing:"easeInCirc"}, 1000);
    }, function(){
    $('#what-text').stop(true, true).hide("slide", {easing:"easeInCirc"}, 1000);
    });
    $('#how-pic').hover(function(){
        $('#how-text').stop(true, true).show("slide", {easing:"easeInCirc"}, 1000);
    }, function(){
        $('#how-text').stop(true, true).hide("slide", {easing:"easeInCirc"}, 1000);
    });
});

回答1:


A simple stop() should work. No need for the 2 true parameters. The parameter of your show and hide methods are not ok.

$(document).ready(function () {
    var options = { easing: "easeInCirc", duration: 1000 };
    $('.div-display').hover(function () {
        $(this).find('.textbox').stop().show(options);
    }, function () {
        $(this).find('.textbox').stop().hide(options);
    });
});

http://jsfiddle.net/rBsLx/12/



来源:https://stackoverflow.com/questions/21235097/how-to-handle-a-hide-show-queue-with-multiple-hidden-divs-smoothly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!