【问题标题】:expand video on hover悬停时展开视频
【发布时间】:2017-01-21 04:33:40
【问题描述】:

我正在尝试让视频在悬停时展开,但它不起作用,我无计可施。

(使用带引导程序的 Dreameaver CC 2015)

$("#wd1").mouseenter(function() {
	vid = document.getElementById("wd1"); 
	posTop = $("#wd1").offset().top;
	posLeft = $("#wd1").offset().left;
	vidWidth = vid.clientWidth;
	vidHeight = vid.clientHeight;
	$("#wd1").remove();
	vidPlayer = document.createElement('div')
	vidPlayer.setAttribute("id", "vpId");
	vidPlayer.style.position = "relative";
	vidPlayer.style.backgroundColor = "rgba(0,0,0,0.9)"
	vidPlayer.style.marginTop = posTop;
	vidPlayer.style.marginLeft = posLeft;
	vidPlayer.innerHTML = '<video src="public_html/media/VerifiableTerrificHind.mp4" width="'+vidWidth+'" height="'+vidHeight+'" autoplay loop type="video.mp4">';
	document.getElementsByTagName('body')[0].appendChild(vidPlayer);
	$("#vpId").hide().fadeIn(2000);
	$("#vpId").animate({width: "100%", height: "auto"}, 500);
});
#wd1:hover {
	z-index:1000;
	margin: 0 auto;
	width: 50vw;
	height: auto;
	display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container-fluid">
	<div class="row">
    <div id="box"></div>
		<div class="col-lg-10 col-lg-offset-1">
    		<div class="row" id="vpDiv">
            	<div class="col-lg-3">
      <video id="wd1" src="https://matthew-williams.000webhostapp.com/media/VerifiableTerrificHind.mp4" alt="my image" width="100%" height="auto" data-video="https://matthew-williams.000webhostapp.com/media/VerifiableTerrificHind.mp4" type="video/mp4">
				</div>
  			</div>
		</div>
	</div>
</div>

https://www.jsnippet.net/snippet/1300/

【问题讨论】:

  • 很抱歉,它应该从浏览器中的当前位置开始扩展,并以垂直和水平居中结束。

标签: jquery video angular-ui-bootstrap dreamweaver


【解决方案1】:

你可以尝试使用:

    #wd1:hover {
    z-index:1000;
    margin: 0 auto;
    width: 50vw;
    height: auto;
    display: block;
    transform: translateX(25%) translateY(25%);
    -webkit-transform: translate(25%, 25%);
     -webkit-transition: all 0.2s linear;
       -moz-transition: all 0.2s linear;
        -ms-transition: all 0.2s linear;
         -o-transition: all 0.2s linear;
            transition: all 0.2s linear;
}

您可以使用translateX()translateY() 的值。

【讨论】:

  • 谢谢你,杰瑞德。实现这些更改以及一些位置、显示和 zIndex 属性更改,并删除一些脚本行,我留下了一个 css :hover 问题。如果我使用 css :hover 用户鼠标必须跟随视频才能正确显示,这就是为什么我选择使用 jquery 首先删除原始视频并从原始用户位置开始创建一个新视频新 div 中的视频并使其展开(即仅使用 .mouseenter() 并具有关闭按钮)。
猜你喜欢
  • 1970-01-01
  • 2020-07-22
  • 1970-01-01
  • 2012-11-29
  • 1970-01-01
  • 2018-11-27
  • 2016-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多