繁体   English   中英

在iphone / ipad上单击固定位置页脚中的事件未被触发

[英]Click Event not being Fired in fixed position footer on iphone/ipad

所以我在iphone / ipad上呈现的页面中的点击事件有些困难。 这在我检查过的所有桌面浏览器以及android中都很有用。 问题在于单击页脚中的LI。 我试图通过以下方法将单击事件附加到页脚元素:

$('#footer li').live('click', function(e) { 

        Site.loadpage($(this).attr('page') + '.html');

});

但没有任何反应(没有javascript错误或任何东西)。 因此,为了获得更多信息,我添加了一个更通用的点击事件,也许我会发现一些其他元素妨碍了捕获事件的方式:

$('*').live('click', function(e) { 

    alert(e.target);

});

有了这个事件,我可以点击我页面上的任何地方,我会收到一个警告,其中包含我点击的元素类型。 除了在页脚中 ,什么都没发生。

这里有一些关于我正在使用它的页面的更多信息,我可以在必要时提供更多信息,唯一可能相关的其他事情是我正在使用jquery(显然)。

我有一个页面具有以下结构:

<body>
        <div id="header">

        </div>

        <div id="content">

        </div>

        <div id="footer">
            <ul>
                <li page="projects" class="projects"><span>Projects</span></li>
                <li page="people" class="people active"><span>People</span></li>    
                <li page="assignments" class="assignments"><span>Assignments</span></li>
                <li page="search" class="search"><span>Search</span></li>
                <li page="more" class="more"><span>More</span></li>
            </ul>
        </div>
</body>

以下CSS:

html { 

    height:100%; 
    width: 100%;
    margin:0; 
    overflow: hidden; 
    padding: 0px; 
    position: fixed;
    text-shadow: 0px 0px 0px transparent !important;
    letter-spacing: 0px;
    font-family: Helvetica;
    font-weight: bold;
}

body { 

    padding: 0px;
    margin: 0px; 
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: Helvetica;
}

#header { 

    background: url(../images/devices/iphone/header.jpg); 
    color: white;
    position: fixed;
    top: 0px;
    left: 0px;
    right: 0px;
    height: 45px; /* ADJUST FOR IPAD */
    box-shadow: -5px -5px 4px 7px #888;
}

#header .center { 

    position: static;
    display: block;
    width: 100%;
    max-height: 45px; /* ADJUST FOR IPAD */
    text-align: center;

}

#header h1.center { margin: 8px 0px 10px 0px; }

#content { 

    position: absolute;
    bottom: 48px;
    top: 45px;
    left: 0px;
    right: 0px;
    overflow: hidden;



}

#footer { 

    background: url(../images/devices/iphone/header.jpg);
    background-size: 48px 100%;
    position: absolute;
    bottom: 0px;
    left: 0px;
    right: 0px;
    height: 48px; /* ADJUST FOR IPAD */
    color: white;
    text-align: center;
}

#footer { text-align: center; }
#footer ul { list-style-type: none; padding-left: 0px; margin-left: auto; margin-right: auto; margin-top: 1px; font-size: 8px; }
#footer li { padding-top: 35px; padding-bottom: 1px; display: inline-block; background-image: url(../images/inactive-menu.png); width: 62px; background-size: 312px; }
#footer li.active { background-image: url(../images/active-menu.png); }
#footer li span { width: 57px; padding-top: 10px; }
#footer li.projects { background-position: 0px 0px;}
#footer li.people { background-position: -62px 0px;}
#footer li.assignments { background-position: -124px 0px;}
#footer li.search { background-position: -187px 0px;}
#footer li.more { background-position: -250px 0px;}

由于某些原因,我不相信iOS中的实时工作。 试试.on(),这应该有效。

$('*').on('click', function(e) { 

    alert(e.target);

});

我有同样的问题。 试图警告这个页脚元素上的事件没有运气。 我偶然尝试过:

$('*').on('touchend', function(e) {});

请注意我使用'touchend'作为我的触发事件并且还设置了:

cursor: pointer;

在iPhone 3GS,iOS 5.1.1上测试。

祝好运。

为什么不使用触摸事件而不是点击事件,这是一个鼠标事件,而不是触摸屏事件 - touchstart和touchend作为触摸屏事件更有意义

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM