[英]Change position of a div with jquery onresize
I'm currently working on a web project for my company and I'm in trouble. 我目前正在为公司的Web项目工作,但遇到了麻烦。 I have code like so:
我有这样的代码:
//CSS
.home-panel{
z-index: 0;
width: 1800px;
height: 2100px;
background: gray;
transform: skew(0deg,-55deg) translateY(-1920px);
}
.ultimate-hero{
height:100vh;
overflow:hidden;
}
//HTML
<div class="ultimate-hero">
<div class="home-panel">
</div>
</div>
//JS
$(window).resize(function() {
//get dimensions
var height = $(window).height();
var width = $(window).width();
$('.home-panel').css({
'transform' : 'skew(0deg,-55deg) translateY(-'+width+'px)'
});
});
I want to move .home-panel
when the browser is resizing, but that code apparently does the reverse from what I expected. 当浏览器调整大小时,我想移动
.home-panel
,但是该代码显然与我期望的相反。 So how do I fix that? 那么我该如何解决呢?
Thank you. 谢谢。
I should mention this earlier, i want something like .home-panel
from this website http://espn.com/espn/feature/story/_/id/19742921/espn-body-issue-2017 or at least closer. 我应该提到这一点早,我想是这样
.home-panel
从本网站http://espn.com/espn/feature/story/_/id/19742921/espn-body-issue-2017或至少接近。 If you have better way to do that, please help me. 如果您有更好的方法,请帮助我。
.home-panel{
z-index: 0;
width: 1800px;
height: 2100px;
background: gray;
/*transform: skew(0deg,-55deg) translateY(-1920px);*/
}
Try to remove transform: skew(0deg,-55deg) translateY(-1920px);
尝试删除
transform: skew(0deg,-55deg) translateY(-1920px);
//JS
$(document).ready(function(){
var height = $(window).height();
var width = $(window).width();
$('.home-panel').css({
'transform' : 'skew(0deg,-55deg) translateY(-'+width+'px)'
});
});
$(window).resize(function() {
//get dimensions
var height = $(window).height();
var width = $(window).width();
$('.home-panel').css({
'transform' : 'skew(0deg,-55deg) translateY(-'+width+'px)'
});
});
Try this: 尝试这个:
$('.home-panel').css({
'transform': 'skew(0deg,-55deg) translateY(-'+(1920+1800- width)+'px)'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.