分离所需效果的问题

时间:2013-12-21 22:32:06

标签: javascript html css

我正在使用.js创建一个俄罗斯娃娃效果。但这似乎有效,从顶部拖动有时会显示一个错误,其中标题与基础分离。我不确定为什么或如何解决。

Fiddle

HTML:

<div class='emails-container'>
<div class='column-header'>
<b>
Still Testing
</b>
<hr>
</div>These should lie on top of each other like a russian doll effect</div>
<div class='emails-container'>
<div class='column-header'>
<b>
Test Me
</b>
<hr>
</div>These should lie on top of each other like a russian doll effect</div>

CSS:

html{font-size:20px;font-family:Helvetica;color:red}.bookmarks-container{width:88%;margin-left:auto;margin-right:auto}.emails-container{padding-top:5px;width:140px;float:left;background-color:white;margin-right:10px;padding-left:10px;border-bottom-left-radius:10px;border-top-right-radius:30px;border:8px solid black; position:absolute; top:50%;left:50%; width:500px; height:500px}.emails-container:hover{border:8px solid red}.links{padding-top:10px;margin-bottom:10px}.links:hover{background-color:#B0E2FF;margin-right:10px}.footer{clear:both;padding-top:30px}.footer-container{margin-left:auto;margin-right:auto;width:50%}hr{color:red;border:4px solid black}a{color:#F87431;font-size:16px}.column-header{margin-top:7px}.header-login{text-align:right;padding-right:20px;float:right}.true-footer{width:40px;height:40px;background-color:white;position:absolute;bottom:20px;border-radius:40px;border:8px solid #1589FF}.true-footer:hover{border:8px solid #F87431}

的javascript:

(function($) {
    $.fn.drags = function(opt) {

        opt = $.extend({handle:"",cursor:"move"}, opt);

        if(opt.handle === "") {
            var $el = this;
        } else {
            var $el = this.find(opt.handle);
        }

        return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
            if(opt.handle === "") {
                var $drag = $(this).addClass('draggable');
            } else {
                var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
            }
            var z_idx = $drag.css('z-index'),
                drg_h = $drag.outerHeight(),
                drg_w = $drag.outerWidth(),
                pos_y = $drag.offset().top + drg_h - e.pageY,
                pos_x = $drag.offset().left + drg_w - e.pageX;
            $drag.css('z-index', 1000).parents().on("mousemove", function(e) {
                $('.draggable').offset({
                    top:e.pageY + pos_y - drg_h,
                    left:e.pageX + pos_x - drg_w
                }).on("mouseup", function() {
                    $(this).removeClass('draggable').css('z-index', z_idx);
                });
            });
            e.preventDefault(); // disable selection
        }).on("mouseup", function() {
            if(opt.handle === "") {
                $(this).removeClass('draggable');
            } else {
                $(this).removeClass('active-handle').parent().removeClass('draggable');
            }
        });

    }
})(jQuery);

$('div').drags();

0 个答案:

没有答案