javascript 不移动元素

发布于 2025-01-01 07:42:08 字数 1423 浏览 2 评论 0原文

我正在尝试制作一个可点击的框来禁用转换 CSS。我正在尝试用 javascript 覆盖 CSS,但它似乎不起作用。我希望他们在单击 后简单地向左和向下移动一点,如果他们只关注 ,他们就会在哪里。

.bigbox {
border: 2px solid black;
border-radius:      20px;
background-color:   blue;
color:  white;
padding-left: 15px;
}
#closebigbox {
padding:    10px;
border: 2px solid black;
border-radius:      20px;
background-color:   blue;
color:  white;
font-size:  8px;
width:  25px;
text-align: left;
background-color:   silver;
}
.bigbox_submit{
padding:    3px;
border: 2px solid black;
border-radius:      20px;
background-color:   blue;
color:  white;
font-size:  12px;
width:  25px;
text-align: left;
background-color:   silver;
}

.bigbox{ 
 -moz-transition: all 0.5s ease-in-out; 
 } 
 .bigbox:focus { 
 background-color: #fc3; 
 -moz-transform: translate(125px,25px) scale(2); 
 }

<a href="javascript: document.getElementsByClassName('bigbox').style.position = 'relative'; document.getElementsByClassName('bigbox').style.left = '125px'; document.getElementsByClassName('bigbox').style.top = '25px';"  id="closebigbox" >Clear</a>

<form>
<input type="text"   class="bigbox" /><br/>
<input type="text"   class="bigbox" /><br/>
<input type="text"   class="bigbox" /><br/>
<a href="javascript:" class="bigbox_submit" >Submit</a>
</form>`

I'm trying make a click-able box to disable the transform CSS. I'm trying to overwrite the CSS with javascript but it dosn't seem to be working. I would like them to simply move to left and down a bit after clicking on the <a>, where they would be if they just focused on the <input>.

.bigbox {
border: 2px solid black;
border-radius:      20px;
background-color:   blue;
color:  white;
padding-left: 15px;
}
#closebigbox {
padding:    10px;
border: 2px solid black;
border-radius:      20px;
background-color:   blue;
color:  white;
font-size:  8px;
width:  25px;
text-align: left;
background-color:   silver;
}
.bigbox_submit{
padding:    3px;
border: 2px solid black;
border-radius:      20px;
background-color:   blue;
color:  white;
font-size:  12px;
width:  25px;
text-align: left;
background-color:   silver;
}

.bigbox{ 
 -moz-transition: all 0.5s ease-in-out; 
 } 
 .bigbox:focus { 
 background-color: #fc3; 
 -moz-transform: translate(125px,25px) scale(2); 
 }

<a href="javascript: document.getElementsByClassName('bigbox').style.position = 'relative'; document.getElementsByClassName('bigbox').style.left = '125px'; document.getElementsByClassName('bigbox').style.top = '25px';"  id="closebigbox" >Clear</a>

<form>
<input type="text"   class="bigbox" /><br/>
<input type="text"   class="bigbox" /><br/>
<input type="text"   class="bigbox" /><br/>
<a href="javascript:" class="bigbox_submit" >Submit</a>
</form>`

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

善良天后 2025-01-08 07:42:08

getElementsByClassName 返回一个数组,因此您需要循环遍历所有元素,然后应用样式:

var _elements = document.getElementsByClassName('bigbox');
for( var i = 0; i < _elements.length; i ++){
    _elements[i].style.position = 'relative'
    _elements[i].style.left= '125px'
    _elements[i].style.top= '25px'
}

getElementsByClassName returns an Array so you'll need to loop through all of the elements and then apply the style:

var _elements = document.getElementsByClassName('bigbox');
for( var i = 0; i < _elements.length; i ++){
    _elements[i].style.position = 'relative'
    _elements[i].style.left= '125px'
    _elements[i].style.top= '25px'
}
深居我梦 2025-01-08 07:42:08

尝试做这样的事情

$('Foo').animate({right:2000px}).delay(3000).animate({left: '0px' });

Try doing something like this

$('Foo').animate({right:2000px}).delay(3000).animate({left: '0px' });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文