覆盖CSS:使用jquery显示无属性 [英] Overwriting CSS : Display none property with jquery
问题描述
对于定义为display的元素:在css中没有,我试图运行一个函数,它试图使用.show()显示元素,代码如下:
CSS
.element {
position:absolute;
display:none;
剩下:0;
top:0;
}
HTML $ b
< div class =element>一些内容在这里< / div>
< div class =element>一些内容在这里< / div>
jQuery
var c = $('。element');
c.each(function(){
c.css({
'left':dleft +'px'
});
c.css({
'top':dtop +'px'
});
c.setTimeout(function(){
c。显示(1000);
},sduration);
所有变量都被填充已经通过提醒所有人并检查了它们的默认值进行了检查,但是不知何故该元素在超时之后没有显示。 解决方案
你有没有关闭.each()循环..另外setTimeout是一个全局函数.. ..检查这个
var dleft = 40;
var dtop = 40;
var sduration = 1000;
var c = $('。element') ;
c.each(function(){
c.css({
'left':dleft +'px',
'top':dtop + 'px'
});
});
setTimeout(function(){
c.show(1000);
},sduration);
For an element defined as display:none in css I am trying to run a function which tries to display the element using .show(), code below:
CSS
.element {
position: absolute;
display: none;
left: 0;
top: 0;
}
HTML
<div class="element">Some content here</div>
<div class="element">Some content here</div>
jQuery
var c = $('.element');
c.each(function () {
c.css({
'left': dleft + 'px'
});
c.css({
'top': dtop + 'px'
});
c.setTimeout(function () {
c.show(1000);
}, sduration);
All the variables are getting populated I have checked by alerting all of them and given them default values as well, but somehow the element is not being shown after the timeout.
There seems to be two problems in the code you have written. you have not closed the .each() loop .. Also setTimeout is a global function.. .. Check this
var dleft = 40;
var dtop = 40;
var sduration = 1000;
var c = $('.element');
c.each(function() {
c.css({
'left': dleft + 'px',
'top': dtop + 'px'
});
});
setTimeout(function() {
c.show(1000);
}, sduration);
Check this FIDDLE
这篇关于覆盖CSS:使用jquery显示无属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!