我正在尝试使用HTML,CSS和Jquery构建音频播放器。我在使用Jquery的“悬停”方法时遇到麻烦。移除“背景图像”后,似乎将div向下移动-为什么这样做?我了解这与页面流程有关。我认为我应该从头开始重新启动音频播放器,因为它有太多错误。我应该只使用CSS悬停吗?
这里是实时site
的链接
.junction {
display: inline;
padding: 2vw;
}
.music-box {
background: url(junction.jpg);
background-size: contain;
background-repeat: no-repeat;
position: relative;
width: 16vw;
cursor: pointer;
height: 30vh;
display: inline-block;
}
.music-details {
display: none;
position: relative;
top: 5vh;
text-transform: uppercase;
font-size: 1vh;
font-family: 'Nunito Sans', sans-serif;
letter-spacing: 0.5px;
font-weight: normal;
}
.appleLink {
height: 3vh;
width: auto;
}
.player {
display: none;
position: relative;
top: 7vh;
}
.buyDiv {
display: none;
height: 3vh;
top: 9vh;
width: auto;
position: relative;
}
.buyList {
position: relative;
padding: 0;
margin: 0;
}
.buyList li {
display: inline;
cursor: pointer;
}
.buyFnt {
text-transform: uppercase;
font-size: 1vh;
font-family: 'Nunito Sans', sans-serif;
letter-spacing: 0.5px;
font-weight: normal;
display: inline;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<li class="junction">
<div class="music-box">
<h3 class="music-details">Junction - EP
<br>
<br>
Turn Around (feat Madi Lane)
<br>
<br>
My Nu Leng - 2018
</h3>
<audio id="player" src="tune.mp3"></audio>
<div class="player">
<button onclick="document.getElementById('player').play()"><img class="playBtn" src="playBtn.png"></button>
<button onclick="document.getElementById('player').pause()"><img class="stopBtn" src="stopBtn.png"></button>
<button onclick="document.getElementById('player').volume += 0.1"><img class="volUp" src="volUp.png"></button> </button>
<button onclick="document.getElementById('player').volume -= 0.1"><img class="volDown" src="volDown.png"></button> </button>
</div>
<div class="buyDiv">
<ul class="buyList">
<li class="buyFnt">BUY</li>
<li><button><img class="appleLink" src="apple.png"></button></li>
</ul>
</div>
</div>
</li>
.dtype
答案 0 :(得分:3)
要使其完美,需要进行一些小的更改。 将float属性和背景位置添加到音乐盒类(.music-box)css中,如下所示:
.music-box{
float:left;
background-position: center !important;
}
这在您的网站上有效,我已经在您的网站上进行了测试。
答案 1 :(得分:1)
可能会受到其他CSS / JS的干扰。我将您的代码复制到https://jsfiddle.net/Lkm4fotd/1/
的小提琴中HTML
<ul class="first-row">
<li class="junction">
<div class="music-box">
<h3 class="music-details">Junction - EP
<br>
<br>
Turn Around (feat Madi Lane)
<br>
<br>
My Nu Leng - 2018
</h3>
<audio id="player" src="tune.mp3"></audio>
<div class="player">
<button onclick="document.getElementById('player').play()"><img class="playBtn" src="playBtn.png"></button>
<button onclick="document.getElementById('player').pause()"><img class="stopBtn" src="stopBtn.png"></button>
<button onclick="document.getElementById('player').volume += 0.1"><img class="volUp" src="volUp.png"></button>
<button onclick="document.getElementById('player').volume -= 0.1"><img class="volDown" src="volDown.png"></button>
</div>
<div class="buyDiv">
<ul class="buyList">
<li class="buyFnt">BUY</li>
<li><button><img class="appleLink" src="apple.png"></button></li>
</ul>
</div>
</div>
</li>
</ul>
CSS:您的CSS文件
JS:
$('.music-box').hover(function() {
$('.music-box').css("border", "1px solid black");
$('.music-box').css("background", "none");
$('.player').css('display', 'block');
$('.music-details').css('display', 'block');
$('.buyDiv').css('display', 'block');
});
$('.music-box').mouseleave(function() {
$('.music-box').css("border", "none");
$('.music-box').css("background", "url('https://benjamingibbsportfolio.000webhostapp.com/junction.jpg')");
$('.music-box').css("background-size", "contain");
$('.music-box').css("background-repeat", "no-repeat");
$('.player').css('display', 'none');
$('.music-details').css('display', 'none');
$('.buyDiv').css('display', 'none');
});