- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我有图像,当您单击它们时它们会展开(通过 css)。但是,我也想要它,以便在您单击时将图像推到页面顶部。据我所知,如果我使用 toggleClass 函数,那么我需要在启动动画之前有一个标志,但是,我似乎无法让它正常运行。
$("img").on("click", function (){
$(this).toggleClass("selected");
if ($("img").hasClass("selected")) {
found = true;
}
var timeout = setTimeout(function () {
$('html,body').animate({
scrollTop: $('.selected').offset().top - 60
}, 100);
}, 5);
});
最佳答案
您应该考虑使用 CSS3 转换而不是使用计时器进行监控。您设置 transition
以转换 top
属性。然后让 selected
类通过切换来更改 top
。更改将导致动画启动。See this example :
HTML:
<div class="bar">weee!</div>
CSS:
.bar{
width: 100px;
height: 100px;
background: red;
position: relative;
transition: top 1s ease 0;
top: 100px;
}
.bar.selected{
top : 0px;
}
JS:
$('.bar').on('click',function(){
$(this).toggleClass('selected');
});
关于javascript - 将标志添加到 javascript (hasClass),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24702583/
第 6 行中 !$catalog.hasClass('catalog-fixed') 的值始终为 true $(window).scroll(function(){ var $catalo
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 9 年前。 Improve
我正在尝试为一个网站开发一个照片库,该网站根据分类法(在本例中,用于描述图片所属的事件)切换图片。 我在存档中呈现了分类法列表,并使用数据属性来保存分类法段,以便稍后作为类使用。 slug . '">
我做了这个 fiddle : http://jsfiddle.net/4CtLV/ 现在,我想做的是,如果选项卡将 selectedTab 作为其类,则显示相应的 div。我已经设置了 if 语句,但
我有多跨度标签,我想测试所有标签是否都有 c2 类,然后发出警报。 if($('.c1').hasClass('c2')) { alert('ok all'); } else ale
我之前使用过 hasClass 方法,但我有一个场景,报告为不存在,尽管如果我输出 elements .html() ,它会清楚地显示该类也被 item 使用和其他类一样。 该类所属的元素也被动态写入
我需要找出有多少个具有“ui-tableFilter-filtered”类; 我尝试了以下方法 updatecounter(table.find("th").hasClass('ui-tableFil
我正在尝试执行以下操作: $('.myEm').closest('.area').hasClass('medium').toggleClass('large-4 large-12'); 但我不断收到错
这是一个动画,仅当 div rip_tab 具有类“rip_tab_ripped”时才会触发,该类在单击 div 后应用。但是,动画甚至在 rip_tab_ripped 类切换之前就已触发。每个函数单
我构建了一个显示/隐藏菜单。效果很好。但默认情况下菜单是关闭的,在导航到该页面之前这一切都很好。 当页面导航到 anchor 时, anchor 是使用“active”类构建的,我想要检查菜单中是否存
你知道为什么在 hasClass 之后使用 removeClass 会给我 Uncaught TypeError: undefined is not a function 吗? 在下面的代码中,警报不
我为页面上的某些选项卡创建了一个简单的背景效果,但不希望在选项卡具有“当前”类时触发该效果。 我认为有一种方法可以使用 .hasClass 来做到这一点 这是我用于实现效果的内容: $('ul.hta
需要满足以下条件才能工作: http://jsfiddle.net/xavi3r/4J583/ $('body').append("" + $('div').hasClass('.active.de
我正在尝试添加一个jquery选择器,它会发现:所有不具有no-hide类的data-toggle=collapse 我尝试了一下,但没有选择任何内容。 $('[data-toggle=collaps
我正在使用名为 JS Scrollpane 的 jQuery 自定义滚动条库,但是当尝试将滚动条应用到已有滚动条的 DIV 时,它会产生意外的结果。所以我想检查的是类“.jspScrollable”是
我希望以下 loadContent 函数仅在单击的链接具有特定类时加载目标 div。这是我到目前为止所想到的: function loadContent(targetDIV, sourceURL) {
在jquery中,我可以将“closest”或Parents()与“hasClass”结合起来,这样它就会给我一个与给定类最接近的元素(如果页面上存在的话)? var matchingDiv = $(
出于某种原因,这没有启动 $(function(){ if ($(h3).hasClass("6") ){ alert ('Todays Date Friday') } }); 最佳答案 $(h
是否有可能以及如何使用 hasClass() 以便我可以搜索以某个指定字符串开头的类? 我想查看多个类,看看是否至少存在一个以字符串开头的类。 string: "old" 这可能吗?您是否也可以进行包
我想知道在 jQuery 中是否有可能知道一个元素是否被点击或 hasClass() 这是我尝试过的,但没有成功 if($('.subCat span[data-value="all"]').hasC
我是一名优秀的程序员,十分优秀!