【发布时间】:2018-11-19 12:22:44
【问题描述】:
我正在尝试通过 Java 脚本获取 div 的宽度和高度,当页面加载时我得到了宽度和高度,但是我将 div 悬停,所以它没有显示宽度/高度更新大小。我需要当 div 悬停时增加宽度或高度也移动/增加并显示 div 大小增加。当我使用/高度 50% 到 100% 制作 css 动画时,我还需要,所以还需要以像素为单位显示宽度/高度动画。
这是我需要的示例。当 div 宽度/高度增加时,也增加顶部黑色区域的值Video Link
$(document).ready(function() {
$("#w-count").html($('.animating-width').width());
$("#h-count").html($('.animating-width').height());
});
html {
background: #292a2b;
color: #FFF;
}
.animating-width {
padding:10px 0;
text-align:center;
background: #e78629;
color: white;
height: 100px;
width: 50%;
-moz-transition: width 2s ease-in-out;
-o-transition: width 2s ease-in-out;
-webkit-transition: width 2s ease-in-out;
transition: width 2s ease-in-out;
}
.animating-width:hover {
cursor: pointer;
width: 100%;
}
hr{
border-color:#e78700;
border-bottom:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="animating-width">on Hover width 100%<hr> <span id="w-count"></span>x<span id="h-count"></span></div>
【问题讨论】:
-
@hasan 你可以试试这个。 api.jquery.com/height这里你会得到一个完整的例子
-
@misorude 我需要
id="w-count"和id="h-count"中的值 -
那么您需要一个间隔或其他东西来不断检查当前值并更新您的输出。
-
现在兄弟,看到这个Link 这是我在悬停div时需要这个的例子,所以告诉我什么是宽度/高度。
标签: javascript jquery css