jqTouch事件处理和函数的奇怪行为

发布于 2024-09-15 23:45:59 字数 2906 浏览 3 评论 0原文

有人能告诉我为什么图片在我想要居中的末尾跳动吗?

http://vertic4l.com/prinzipalmarkt/mobile.php

这是一个移动网站,我'我正在处理,如果输入第一个 li 元素, 将触发一个函数。但它并没有像它应该的那样工作...

我已经在正常的网站上做到了这一点,没有遇到很多麻烦 (vertic4l.com/prinzipalmarkt/index.php)。 但现在我不知道应该在哪里解决这个问题。

如果输入第一个 li 元素:

将检查视口,然后设置尺寸,图像将居中,最后 div 中的叠加层消失并从 DOM 中删除。

但最后几点不想做他们应该做的事。 此外,我必须触发第二次点击或必须手动执行 否则所有图像将不会居中。 :/

这是代码:

jQuery(function(){
            jQuery('body').bind('turn', function(event, info){
                var windowWidth = $(window).width();
                if(windowWidth >= 450){
                    jQuery(".dcontent").each(function(){
                        jQuery(this).css({
                            'width' : '450px'
                        });
                    });
                }
                else{
                    jQuery(".dcontent").each(function(){
                        jQuery(this).css({
                            'width' : '310px'
                        });
                    });
                }
            });

            jQuery('#kaufleute').bind('changeState',function(){
                var windowWidth = $(window).width();
                if(windowWidth >= 450){
                    jQuery("#kasten").css({'width' : '460px'});
                    jQuery(".img_center").each(function(){
                        var $li = jQuery(this), $img = $li.find('img');
                        $li.css({
                            'margin-right' : '4px',
                            'margin-bottom' : '4px',
                            'width' : '145px',
                            'height' : '145px',
                        });
                        $img.css('padding-top', ($li.height() / 2) - ($img.height() / 2));
                    });
                }
                else{
                    jQuery(".img_center").each(function(){
                        jQuery("#kasten").css({'width' : '320px'});
                        var $li = jQuery(this), $img = $li.find('img');
                        $li.css({
                            'margin-right' : '6px',
                            'margin-bottom' : '6px',
                            'width' : '150px',
                            'height' : '150px'
                        });
                        $img.css('padding-top', ($li.height() / 2) - ($img.height() / 2));
                    });
                }
                jQuery(".overlay_pic").animate({opacity: 0}, 2000, 'swing').queue(function(){
                    jQuery(this).remove();
                });
            });
            jQuery('.page').click(function(){
                jQuery('#kaufleute').trigger('changeState');
                jQuery('#kaufleute').trigger('turn');
            });
        });

有人可以帮助我吗?

Can someone tell me why the pictures are jumping at the end which i want to center?

http://vertic4l.com/prinzipalmarkt/mobile.php

Here is a mobile website i'm working on, if the first li element is entered,
a function will be triggered. But it doesn't works like it should...

I already did this on the normal website without a lot trouble
(vertic4l.com/prinzipalmarkt/index.php).
But now i dont have any idea where i should look at for solving that issue.

If first li element is entered:

viewport will be checked, then dimensions set, images will be centered, and finally the overlayin div fades away and will be removed from DOM.

But these last points dont wanna do like they should.
Further more i got to trigger a 2nd click or have to do it manually
otherwise all images will not be centered. :/

Here is the Code:

jQuery(function(){
            jQuery('body').bind('turn', function(event, info){
                var windowWidth = $(window).width();
                if(windowWidth >= 450){
                    jQuery(".dcontent").each(function(){
                        jQuery(this).css({
                            'width' : '450px'
                        });
                    });
                }
                else{
                    jQuery(".dcontent").each(function(){
                        jQuery(this).css({
                            'width' : '310px'
                        });
                    });
                }
            });

            jQuery('#kaufleute').bind('changeState',function(){
                var windowWidth = $(window).width();
                if(windowWidth >= 450){
                    jQuery("#kasten").css({'width' : '460px'});
                    jQuery(".img_center").each(function(){
                        var $li = jQuery(this), $img = $li.find('img');
                        $li.css({
                            'margin-right' : '4px',
                            'margin-bottom' : '4px',
                            'width' : '145px',
                            'height' : '145px',
                        });
                        $img.css('padding-top', ($li.height() / 2) - ($img.height() / 2));
                    });
                }
                else{
                    jQuery(".img_center").each(function(){
                        jQuery("#kasten").css({'width' : '320px'});
                        var $li = jQuery(this), $img = $li.find('img');
                        $li.css({
                            'margin-right' : '6px',
                            'margin-bottom' : '6px',
                            'width' : '150px',
                            'height' : '150px'
                        });
                        $img.css('padding-top', ($li.height() / 2) - ($img.height() / 2));
                    });
                }
                jQuery(".overlay_pic").animate({opacity: 0}, 2000, 'swing').queue(function(){
                    jQuery(this).remove();
                });
            });
            jQuery('.page').click(function(){
                jQuery('#kaufleute').trigger('changeState');
                jQuery('#kaufleute').trigger('turn');
            });
        });

Can anybody help me out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文