如果你想添加的風格,那麼我會建議使用一個媒體查詢,您可以針對該類fa-4x
與選擇的強鏈,如果需要的話。 How CSS selectors work:
您可以使用像這樣:
.fa-5x {
background-color: #000000;
padding: 40px;
}
@media only screen and (max-width: 767px) {
.fa-twitter-square.fa-4x {
background-color: #ff0000;
padding: 0 20px 0;
}
}
如果你真的想使用JS,那麼你可以做這樣的事情上面:
$(function() {
var width = window.innerWidth;
if (width < 768) {
$(".fa-facebook-square, .fa-twitter-square")
.removeClass('fa-5x')
.addClass('fa-4x');
}
});
如果你需要留意的情況下調整你需要一個響應網站,你需要等待任何調整大小事件,然後調用一個函數來做你想做的事情。
var over767px = function() {
var windowWidth = window.innerWidth;
if (windowWidth > 767) {
//perform tablet/desktop code here
} else if (windowWidth < 768) {
//perform mobile code here
}
};
var debouncer = function(func , timeout) {
var timeoutID , timeout = timeout || 50;
return function() {
var scope = this , args = arguments;
clearTimeout(timeoutID);
timeoutID = setTimeout(function() {
func.apply(scope , Array.prototype.slice.call(args));
} , timeout);
};
};
$(window).resize(debouncer(function (e) {
over767px();
}));
有什麼用意?你可以用純CSS通過媒體查詢實現你想要的任何樣式:'@media only screen and(min-width:768px)' –