我玩的網頁看起來像這樣的投資組合部分:如何使用特定過濾器鏈接到投資組合頁面?
$(function() {
var selectedClass = "";
$(".fil-cat").click(function() {
selectedClass = $(this).attr("data-rel");
$("#portfolio").fadeTo(100, 0.1);
$("#portfolio div").not("." + selectedClass).fadeOut().removeClass('scale-anm');
setTimeout(function() {
$("." + selectedClass).fadeIn().addClass('scale-anm');
$("#portfolio").fadeTo(300, 1);
}, 300);
});
});
body {
max-width: 900px;
float: none;
margin: auto;
}
#portfolio {
margin: 1rem 0;
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-gap: 1rem;
-moz-column-gap: 1rem;
column-gap: 1rem;
-webkit-column-width: 33.33333333333333%;
-moz-column-width: 33.33333333333333%;
column-width: 33.33333333333333%;
}
.tile {
-webkit-transform: scale(0);
transform: scale(0);
-webkit-transition: all 350ms ease;
transition: all 350ms ease;
}
.tile:hover {}
.scale-anm {
transform: scale(1);
}
p {
padding: 10px;
border-bottom: 1px #ccc dotted;
text-decoration: none;
font-family: lato;
text-transform: uppercase;
font-size: 12px;
color: #333;
display: block;
float: left;
}
p:hover {
cursor: pointer;
background: #333;
color: #eee;
}
.tile img {
max-width: 100%;
width: 100%;
height: auto;
margin-bottom: 1rem;
}
.btn {
font-family: Lato;
font-size: 1rem;
font-weight: normal;
text-decoration: none;
cursor: pointer;
display: inline-block;
line-height: normal;
padding: .5rem 1rem;
margin: 0;
height: auto;
border: 1px solid;
vertical-align: middle;
-webkit-appearance: none;
color: #555;
background-color: rgba(0, 0, 0, 0);
}
.btn:hover {
text-decoration: none;
}
.btn:focus {
outline: none;
border-color: var(--darken-2);
box-shadow: 0 0 0 3px var(--darken-3);
}
::-moz-focus-inner {
border: 0;
padding: 0;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://npmcdn.com/[email protected]/css/basscss.min.css" rel="stylesheet" />
<div class="toolbar mb2 mt2">
<button class="btn fil-cat" href="" data-rel="all">All</button>
<button class="btn fil-cat" data-rel="web">Websites</button>
<button class="btn fil-cat" data-rel="flyers">Flyers</button>
<button class="btn fil-cat" data-rel="bcards">Business Cards</button>
</div>
<div style="clear:both;"></div>
<div id="portfolio">
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm bcards all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm flyers all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm bcards all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
<div class="tile scale-anm flyers all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
<div class="tile scale-anm flyers all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm bcards all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm bcards all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm web all">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" />
</div>
<div class="tile scale-anm bcards all">
<img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" />
</div>
</div>
<div style="clear:both;"></div>
從不同的網頁我有一個鏈接到投資組合部分的按鈕。但我想要的是一個按鈕(在不同的頁面),它已經到了投資組合,已經過濾到某個元素。例如,我想從另一頁面將用戶直接帶到「傳單」元素,因此不必過濾任何內容。可能嗎?我怎樣才能做到這一點?
編輯
試圖對標記爲正確的,我注意到它正在一個特定情況下的答案解決方案之後,一個爲working
這是我加的東西,每當我改變我的鏈接過於/our-work#other-case
頁面提出,但沒有相應的過濾
$(document).ready(function() {
var hash = window.location.hash.substr(1);
switch(hash){
case 'case-one':
$(this).scrollTop(0);
$('#case-one').click();
case 'working':
$(this).scrollTop(0);
$('#working').click();
case 'case-two':
$(this).scrollTop(0);
$('#case-two').click();
case 'case-three':
$(this).scrollTop(0);
$('#case-three').click();
case 'case-four':
$(this).scrollTop(0);
$('#case-four').click();
}
});
爲什麼這不優雅? –
假設有一個比在你的URL中使用散列更好的方法。我知道這工作雖然! – lloyd
嗨,我注意到由於某種原因使用這個解決方案只適用於一種情況'working' –