- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将这个整洁的 header 添加到我的站点:http://tympanus.net/codrops/2010/05/18/little-boxes-menu-with-jquery/
一个问题是 javascript 使所有链接都以与小框相同的方式进行动画处理,因此我在标题中包含的任何链接都将变为动画。我在 Stack Overflow 上找到了一个线程,它提供了一些解决方案。在找到一个似乎有效的方法后,我发现盒子一旦展开就不再有动画效果。当您单击框 div 将其关闭时,它会刷新页面。
我想找到一种在不影响动画效果的情况下包含链接的方法。
这是 Javascript:
$(function() {
/* object to save the initial positions of each box */
var divinfo = {"initial": []};
/* index of the selected / clicked box */
var current = -1;
/* we save the index,top and left of each box */
$('#littleBoxes > div','staffer').each(function(){
$('staffer').removeClass('#littleBoxes a').addClass('#staffer a');
var $this = $(this);
var initial = {
'index' : $this.index(),
'top' : $this.css('top'),
'left' : $this.css('left')
};
divinfo.initial.push(initial);
});
/* click event for the anchors inside of the boxes */
$('#littleBoxes a').bind('click',function(e){
var $this = $(this);
var $currentBox = $this.parent();
/* set a z-index lower than all the other boxes,
to see the other boxes animation on the top*/
$currentBox.css('z-index','1');
/* if we are clicking on an expanded box: */
if(current == $currentBox.index()){
/* put it back (decrease width, height,
and set the top and left back)
the previous positions are saved in the divinfo obj*/
$currentBox.stop().animate({
'top' : divinfo.initial[$currentBox.index()].top,
'left' : divinfo.initial[$currentBox.index()].left,
'width' : '90px',
'height' : '90px'
},800,'easeOutBack').find('.boxcontent').fadeOut();
$('#littleBoxes > div').not($currentBox).each(function(){
var $ele = $(this);
var elemTop = divinfo.initial[$ele.index()].top;
var elemLeft = divinfo.initial[$ele.index()].left;
$ele.stop().show().animate({
'top' : elemTop,
'left' : elemLeft,
'opacity' : 1
},800);
});
current = -1;
}
/* if we are clicking on a small box : */
else{
/* randomly animate all the other boxes.
Math.floor(Math.random()*601) - 150 creates a random
number between -150 and 450. This range is considering
the initial lefts/tops of the elements. It's not the exact
range, since we would have to calculate the range
based on each one of the boxes. Anyway, it fits our needs...
*/
$('#littleBoxes > div').not($currentBox).each(function(){
var $ele = $(this);
$ele.stop().animate({
'top' : (Math.floor(Math.random()*601) - 150) +'px',
'left': (Math.floor(Math.random()*601) - 150) +'px',
'opacity':0
},800,function(){
$(this).hide();
});
});
/* expand the clicked one;
also, fadeIn the content (boxcontent)
*/
var newwidth = 945;
var newheight = 375;
$currentBox.stop().animate({
'top' : '0px',
'left' : '0px',
'width' : newwidth +'px',
'height': newheight+'px'
},800,'easeOutBack',function(){
current = $currentBox.index();
$(this).find('.boxcontent').fadeIn();
});
}
e.preventDefault();
});
});
这是 CSS:
.littleBoxes {
width:1000px;
height:343px;
margin:0 auto;
position:relative;
}
.littleBoxes > div {
position:absolute;
width:90px;
height:90px;
text-align:center;
border:2px solid #F7F7FF;
overflow:hidden;
-moz-box-shadow:0px 0px 3px #555;
-webkit-box-shadow:0px 0px 3px #555;
box-shadow:0px 0px 3px #555;
background-position:center center;
z-index:999;
}
.littleBoxes div a.logobox {
text-transform: uppercase;
font-size: 120%;
font-weight: normal;
font-family: Oswald, sans serif;
letter-spacing: 1px;
display: block;
line-height: 90px;
text-decoration: none;
color: #F7F7FF;
background-image: linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
background-image: -o-linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
background-image: -moz-linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
background-image: -webkit-linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
background-image: -ms-linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
background-image: -webkit-gradient( linear, right bottom, left top, color-stop(0.05, #111111), color-stop(0.5, #2A2D34), color-stop(0.95, #111111) );
outline: none;
}
.littleBoxes div.boxcontent{
height:380px;
text-align:left;
padding:10px;
font-size:100%;
color: #333232;
background-color:#F7F7FF;
border:2px solid #F7F7FF;
margin:0px 0px 0px 0px;
text-shadow:1px 1px 1px #fff;
-moz-box-shadow:1px 1px 3px #777;
-webkit-box-shadow:1px 1px 3px #777;
box-shadow:1px 1px 3px #777;
opacity:0.9;
display:none;
}
.boxcontent .boxinfo {
display: inline-block;
background: #F7F7FF;
width: 46%;
height: 200px;
text-align: justify;
overflow-y: auto;
padding: 10px;
margin-top: -20px;
}
.boxcontent .boxstaff {
float: right;
width: 46%;
}
.boxinfo b {
font-size: 105%;
text-shadow: #333232 0 1px 1px;
background: linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.boxcontent div a {
display: inline;
background: transparent;
}
.bg1, .bg2, .bg3, .bg4{
background-repeat:no-repeat;
}
.bg1{
background-image:url(../images/1.jpg);
}
.bg2{
background-image:url(../images/2.jpg);
}
.bg3{
background-image:url(../images/3.jpg);
}
.bg4{
background-image:url(../images/4.jpg);
}
.bg5{
background-image:url(../images/5.jpg);
}
#staffer h1 {
display: block;
margin-top: -20px;
text-align: center;
text-transform: uppercase;
text-shadow: #333232 0 1px 1px;
background: linear-gradient(right bottom, #111111 5%, #2A2D34 50%, #111111 95%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
#staffer h2 {
display: block;
width: 120px;
text-align: center;
text-transform: uppercase;
margin-top: -25px;
}
#staffer img {
margin: -20px;
border: 2px solid #fff;
-webkit-filter: grayscale(100%); filter: grayscale(100%);
transition: all, 1s;
-moz-transition: all, 1s;
-webkit-transition: all, 1s;
}
#staffer img:hover {
-webkit-filter: grayscale(0%); filter: grayscale(0%);
}
最佳答案
好吧,我开始工作了。
我只是拿了原始(工作)代码,与您的代码进行了比较,发现了一些差异。
首先,不知道为什么,你用的是bind()
方法而不是on()
。根据 jQuery 的官方文档,后者是首选。
其次,您更改了容器的大小,单击菜单时应打开容器。这是一个正确的更改。
最后,导致失败的主要变化是以下代码。你改变了这个:
$('#littleBoxes > div').each(function() {
通过这个:
$('#littleBoxes > div', 'staffer').each(function() {
$('staffer').removeClass('#littleBoxes a').addClass('#staffer a');
有一些问题。
staffer
的标签解决问题后,我让它开始工作。
更新我还注意到,单击打开内容内的链接也会使菜单动画化,这是不需要的(IMO)。所以我更改了选择器,使其不是针对所有链接,而是针对具有 .logobox
类的链接。
这是工作结果。
$(function() {
/* object to save the initial positions of each box */
var divinfo = {
"initial": []
};
/* index of the selected / clicked box */
var current = -1;
/* we save the index,top and left of each box */
$('#littleBoxes > div').each(function() {
$('#staffer').removeClass('#littleBoxes a').addClass(
'#staffer a');
var $this = $(this);
var initial = {
'index': $this.index(),
'top': $this.css('top'),
'left': $this.css('left')
};
divinfo.initial.push(initial);
});
/* click event for the anchors inside of the boxes */
$('#littleBoxes a.logobox').bind('click', function(e) {
var $this = $(this);
var $currentBox = $this.parent();
/* set a z-index lower than all the other boxes,
to see the other boxes animation on the top*/
$currentBox.css('z-index', '1');
/* if we are clicking on an expanded box: */
if (current == $currentBox.index()) {
/* put it back (decrease width, height,
and set the top and left back)
the previous positions are saved in the divinfo obj*/
$currentBox.stop().animate({
'top': divinfo.initial[$currentBox.index()]
.top,
'left': divinfo.initial[$currentBox.index()]
.left,
'width': '90px',
'height': '90px'
}, 800, 'easeOutBack').find('.boxcontent').fadeOut();
$('#littleBoxes > div').not($currentBox).each(
function() {
var $ele = $(this);
var elemTop = divinfo.initial[$ele.index()]
.top;
var elemLeft = divinfo.initial[$ele.index()]
.left;
$ele.stop().show().animate({
'top': elemTop,
'left': elemLeft,
'opacity': 1
}, 800);
});
current = -1;
}
/* if we are clicking on a small box : */
else {
/* randomly animate all the other boxes.
Math.floor(Math.random()*601) - 150 creates a random
number between -150 and 450. This range is considering
the initial lefts/tops of the elements. It's not the exact
range, since we would have to calculate the range
based on each one of the boxes. Anyway, it fits our needs...
*/
$('#littleBoxes > div').not($currentBox).each(
function() {
var $ele = $(this);
$ele.stop().animate({
'top': (Math.floor(Math.random() *
601) - 150) + 'px',
'left': (Math.floor(Math.random() *
601) - 150) + 'px',
'opacity': 0
}, 800, function() {
$(this).hide();
});
});
/* expand the clicked one;
also, fadeIn the content (boxcontent)
*/
var newwidth = 945;
var newheight = 375;
$currentBox.stop().animate({
'top': '0px',
'left': '0px',
'width': newwidth + 'px',
'height': newheight + 'px'
}, 800, 'easeOutBack', function() {
current = $currentBox.index();
$(this).find('.boxcontent').fadeIn();
});
}
e.preventDefault();
});
});
#logo {
display: block;
height: 380px;
width: 950px;
background: #F7F7FF;
background-image: url(http://thoseleftbehind.b1.jcink.com/uploads/thoseleftbehind/Images/amlogo.jpg);
background-size: cover;
background-attachment: fixed;
margin: 0 auto;
margin-top: 50px
}
.littleBoxes {
width: 1000px;
height: 343px;
margin: 0 auto;
position: relative
}
.littleBoxes > div {
position: absolute;
width: 90px;
height: 90px;
text-align: center;
border: 2px solid #F7F7FF;
overflow: hidden;
-moz-box-shadow: 0 0 3px #555;
-webkit-box-shadow: 0 0 3px #555;
box-shadow: 0 0 3px #555;
background-position: center center;
z-index: 999
}
.littleBoxes div a.logobox {
text-transform: uppercase;
font-size: 120%;
font-weight: 400;
font-family: Oswald, sans serif;
letter-spacing: 1px;
display: block;
line-height: 90px;
text-decoration: none;
color: #F7F7FF;
background-image: linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
background-image: -o-linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
background-image: -moz-linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
background-image: -webkit-linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
background-image: -ms-linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
background-image: -webkit-gradient(linear, right bottom, left top, color-stop(0.05, #111), color-stop(0.5, #2A2D34), color-stop(0.95, #111));
outline: none
}
.littleBoxes div.boxcontent {
height: 380px;
text-align: left;
padding: 10px;
font-size: 100%;
color: #333232;
background-color: #F7F7FF;
border: 2px solid #F7F7FF;
margin: 0;
text-shadow: 1px 1px 1px #fff;
-moz-box-shadow: 1px 1px 3px #777;
-webkit-box-shadow: 1px 1px 3px #777;
box-shadow: 1px 1px 3px #777;
opacity: .9;
display: none
}
.boxcontent .boxinfo {
display: inline-block;
background: #F7F7FF;
width: 46%;
height: 200px;
text-align: justify;
overflow-y: auto;
padding: 10px;
margin-top: -20px
}
.boxcontent .boxstaff {
float: right;
width: 46%
}
.boxinfo b {
font-size: 105%;
text-shadow: #333232 0 1px 1px;
background: linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent
}
.boxcontent div a {
display: inline;
background: transparent
}
.bg1,
.bg2,
.bg3,
.bg4 {
background-repeat: no-repeat
}
.bg1 {
background-image: url(../images/1.jpg)
}
.bg2 {
background-image: url(../images/2.jpg)
}
.bg3 {
background-image: url(../images/3.jpg)
}
.bg4 {
background-image: url(../images/4.jpg)
}
.bg5 {
background-image: url(../images/5.jpg)
}
#staffer h1 {
display: block;
margin-top: -20px;
text-align: center;
text-transform: uppercase;
text-shadow: #333232 0 1px 1px;
background: linear-gradient(right bottom, #111 5%, #2A2D34 50%, #111 95%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent
}
#staffer h2 {
display: block;
width: 120px;
text-align: center;
text-transform: uppercase;
margin-top: -25px
}
#staffer img {
margin: -20px;
border: 2px solid #fff;
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
transition: all, 1s;
-moz-transition: all, 1s;
-webkit-transition: all, 1s
}
#staffer img:hover {
-webkit-filter: grayscale(0%);
filter: grayscale(0%)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<div id="logo">
<div class="littleBoxes" id="littleBoxes">
<div class="boxlink bg1" style="top:0px;left:0px;">
<a class="logobox" href="">About</a>
<div class="boxcontent">
<p></p>
<div class="boxinfo">
<b>Those Left Behind is a zombie survival RPG</b> based in the fictional Massachusetts city of Acheron.
<br>
<br>In November of 2014, the dead began to rise and the human population found itself tested. Most major cities fell to the undead, but a few quarantine zones have managed to stay afloat due to military protection. Now the year is 2034 and, as you
might expect, the times have twisted many people into hardened survivalists.
<br>
<br>Those in the quarantine zones are offered protection by what's left of the U.S. military, but it comes at the cost of many of their freedoms and dignities. Meanwhile, corruption from both the military and criminal organizations makes it difficult
to live even within areas deemed safe.
<br>
<br>How will you survive in a world where you're one of those left behind?
</div>
<div class="boxstaff">
<div id="staffer">
<h1>Staff</h1>
<h2>Amy</h2>
<a href="http://thoseleftbehind.jcink.net/index.php?showuser=2" target="_blank">
<img src="http://i.imgur.com/5HN9d6Z.jpg">
</a>
</div>
</div>
<p>
</div>
</div>
<div class="bg5" style="background-position:-90px 0;top:0px;left:95px;"></div>
<div class="bg5" style="background-position:-180px 0;top:0px;left:190px;"></div>
<div class="bg5" style="background-position:-270px 0;top:0px;left:285px;"></div>
<div class="bg5" style="background-position:0 -90px;top:95px;left:0px;"></div>
<div class="boxlink bg2" style="top:95px;left:95px;">
<a class="logobox" href="">Groups</a>
<div class="boxcontent">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="bg5" style="background-position:-180px -90px;top:95px;left:190px;"></div>
<div class="bg5" style="background-position:-270px -90px;top:95px;left:285px;"></div>
<div class="bg5" style="background-position:0 -180px;top:190px;left:0px;"></div>
<div class="bg5" style="background-position:-90px -180px;top:190px;left:95px;"></div>
<div class="boxlink bg3" style="top:190px;left:190px;">
<a class="logobox" href="">News</a>
<div class="boxcontent">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:285px;"></div>
<div class="bg5" style="background-position:0 -270px;top:285px;left:0px;"></div>
<div class="bg5" style="background-position:-90px -270px;top:285px;left:95px;"></div>
<div class="bg5" style="background-position:-180px -270px;top:285px;left:190px;"></div>
<div class="boxlink bg4" style="top:285px;left:285px;">
<a class="logobox" href="">Credits</a>
<div class="boxcontent">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="bg5" style="background-position:-270px -180px;top:0px;left:380px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:95px;left:380px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:380px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:285px;left:380px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:0px;left:475px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:95px;left:475px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:475px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:285px;left:475px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:0px;left:570px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:95px;left:570px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:570px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:285px;left:570px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:0px;left:665px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:95px;left:665px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:665px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:285px;left:665px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:0px;left:760px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:95px;left:760px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:760px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:285px;left:760px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:0px;left:855px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:95px;left:855px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:190px;left:855px;"></div>
<div class="bg5" style="background-position:-270px -180px;top:285px;left:855px;"></div>
</div>
</div>
关于javascript - littleBoxes JQuery 代码中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29026062/
我有一个网站,并且我使用 javascript sdk 添加了“点赞”按钮。 这是代码 (function(d, s, id) { var js, fjs = d.g
我知道 HTML 是逐行读取的。当您链接多个 css 文件(如规范化文件和样式表文件)时,由于 CSS 重要性特异性和源顺序,样式表文件应链接在规范化文件之后。看起来这不会影响链接的 JavaScri
我正在使用官方 Bootstrap site 提供的 CDN 链接在我的网络应用程序中使用面板进行测试 在彻底检查我的代码后,面板没有显示。 但是我在 SO 上看到了类似的帖子并且 CDN 链接不同
这里是编码初学者。我正在尝试为我的移动设备网站设置断点,以便我的网站适合小屏幕。我只是想检查如果我缩小视口(viewport)的宽度,背景颜色是否会改变,但没有发生任何变化。也许我只是对一个简单的错误
举一个我想要的例子,想象一下这个字符串: $text = 'lorem ipsum About us lorem ipsum'; 如果此字符串包含一个 href 以 / 开头的 anchor 链接,则
如何链接到 LaTeX 文档的另一部分或子部分?这种链接的常规范式是什么,像[链接名称]那样写,或者像网页超链接那样写? 最佳答案 链接到另一个部分需要您的部分进行一些额外的标记。要使用的命令是: \
我有一个订单表,其中包含订单号、客户 ID 和代理 ID。然后有一个带有 id 的客户表和一个带有 id 的代理表。 我需要获取所有具有来自代理 ID 'a03' 和代理 ID 'a05' 的订单的客
假设我有: dic = {"z":"zv", "a":"av"} ## Why doesn't the following return a sorted list of keys? keys = d
我在尝试链接到外部库时得到了一些奇怪的结果。如果我从命令行运行以下命令: gcc fftwTest.c -I../extlib/fftw-3.3.5-dll32 -L../extlib/fftw-3.
我认为我没有正确理解 jQuery 链接。我正在遍历一个数组并尝试将 div 元素添加到我的包装器 CSS 类中,每个 div 元素都有一个“click”类和自定义 css top 和 left 属性
HTML 使用超级链接与网络上的另一个文档相连。几乎可以在所有的网页中找到链接。点击链接可以从一张页面跳转到另一张页面。 HTML 超链接(链接) HTML使用标签 a 来设置超文本链接。 超链
这个问题在这里已经有了答案: How do I link to part of a page? (hash?) (7 个答案) Scroll Automatically to the Bottom
我想创建一个 Docker Swarm 集群,运行一个 Elasticsearch 实例、一个 MongoDB 实例和一个 grails 应用程序,每个都在单独的机器上。我正在使用 Docker Ma
我正在尝试将 CakePHP HTML Linker 用于以下代码 Add Cuisine 由于 span 标签需要在 a 标签内。我无法根据需要获得输出。关于如何完成它的任何建议? 最佳答案 禁用链
大家好, 我最近开发了一个应用程序,很快就会提交到 App Store。我想免费提交这个应用程序,并想知道我是否可以实现一个带有 PayPal 捐赠标志的按钮,上面基本上写着“捐赠用于开发”或与此相关
我想尝试在 dlang 中使用 libuv。我下载了这样的 dlang 绑定(bind): git clone git@github.com:tamediadigital/libuv.git 现在我接
我有一个节点(节点 a),各种其他节点(节点 b/c/d/e)与之引用。 我可以创建一个带有参数的 View 作为我正在查看的节点(节点 a),并获取引用该节点的节点列表。 基本上在节点 a 查看节点
我正在尝试建立一个常见问题页面,上面有目录,下面有答案。我想点击目录中的一个问题,并在同一页面上链接到相应的答案。我如何在 CakePHP 中使用 $this->Html->link() 执行此操作方
在 WooCommerce 3.0+ 中,我使用 js 创建了一些选项卡,每个选项卡中包含来自不同类别的产品。我已经设法修改了简单产品的添加到购物车链接,其中点击了 addtocart 按钮它进入下一
Delphi 2007/2009 奇怪的问题在这里: 根据设计时定义的组件属性,是否可以在链接中包含文件或保留文件? 示例:如果我将 SomeProperty 保留为真,则在编译时,单元 SomeUn
我是一名优秀的程序员,十分优秀!