javascript - 按钮不从中心动画

标签 javascript jquery html css animation

因此,当我使用 jquery 为一些填充设置动画而不是动画时,就好像 anchor 是从中心开始的那样,它从左上角开始设置动画。所有代码和 JSFiddle 链接都在下方。

JSFiddle

HTML:

<div id="gaming-news-info">
    <a id="news-button" style="cursor:pointer;">Go to News section</a>
</div>

CSS:

#gaming-news-info {
    position: absolute;
    z-index: 999;
    width: 400px;
    height: 200px;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    margin-top: -100px;
}

#news-button {
    background-color: #4CAF50;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    position: absolute;
    margin-top: 130px;
    font-family: "Prompt-SemiBold";
    margin-left: 90px;
}

最佳答案

您不需要 jquery/javascript 来实现简单的悬停效果。 CSS3 转换和转换完全能够在没有脚本库开销的情况下做同样的事情....

#gaming-news-info {
    position: absolute;
    z-index: 999;
    width: 400px;
    height: 200px;
    top: 50%;
    left: 50%;
	transform: translateX(-50%) translateY(-50%);
	margin-top: -100px;
}

#news-button {
    background-color: #4CAF50;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    position: absolute;
    margin-top: 130px;
    font-family: "Prompt-SemiBold";
	  margin-left: 90px;
	transform: scale(1);
	transition: all .2s;
}

#news-button:hover {
	transform: scale(1.05);
	transition: all .2s;
}
<div id="gaming-news-info">
  <a id="news-button" style="cursor:pointer;">Go to News section</a>
</div>

关于javascript - 按钮不从中心动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39460496/

相关文章:

javascript - ExtJS:将网格面板添加到表格布局会弄乱表格列宽

javascript - 在发送电子邮件之前在 Firestore 函数中合并 Firebase Firestore 查询结果

javascript - 如何使用wrap()来wrap()两个嵌套的div?

javascript - 设置隐藏字段的值不适用于 jQuery

javascript - 为什么即使两个 URL 都来自 XXXX.com,我仍然收到 405 错误?

javascript - 类型 '() => JQuery<HTMLElement>' 的参数不可分配给类型的参数

jquery - 向左过渡幻灯片

javascript - 将源设置为天蓝色媒体播放器

javascript - 如何检索呈现的填充值

html - 最佳实践 : Is it vital that 'http:' is put at the beginning of html links?