忽然笑
2024-01-18 14:51:34
1 - 我建議您使用規則flex。將其添加到您的 CSS 中:#message{ display: flex; align-items: center; justify-content: center;}2 - 從此標簽中刪除styles屬性和樣式p:<p style="margin-bottom:auto;text-align:center;">...</p>3 - 此外,您的span #message標簽是display: inline動態的。您需要在javascript或中禁用此功能jquery?;蛘?important用于:display: flex_#message#message{ display: flex!important; ...}如果您遵循我的回答,那么您的綠色標題的內容會看起來不錯。.ShowHide { overflow: hidden; background-color: #2a4735; color: white;}#left-showing { overflow: hidden;}#right-showing { float: right; width: 30px; text-align: center;}.ShowHide a { color: white; text-decoration: none;}.ShowHide a:hover { text-decoration:underline;}#message{ display: flex; align-items: center; justify-content: center;}@media screen and (max-width: 425px){ #message{font-size:10px;} .shippingimage{display:none;}}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div class="ShowHide" id="Bar"> <div id="right-showing"> <a href="#" onclick="Hide(Bar);">X</a> </div> <div id="left-showing"> <p> <span id="message"></span></p> <script type="text/javascript"> function nextMsg(index) { if (messages.length === index) { nextMsg(0); } else { $('#message').html(messages[index]).fadeIn(1000).delay(2000).fadeOut(1000, ()=> nextMsg(index+1)); } }; var messages = [ '<img src="https://i.imgur.com/bcq9ydY.png" width="30px" class="shippingimage"><a href="https://www.fermento24.com/pages/spedizione" style="letter-spacing: -0.5px;vertical-align: super;">Consegna gratuita in giornata a Napoli, Caserta e relative province sopra i 25€</a>', '<img src="https://i.imgur.com/pSAQiQp.png" width="35px" class="shippingimage"><a href="https://www.fermento24.com/pages/spedizione" style="vertical-align: super;"> Spedizione gratuita nel resto d’Italia sopra i 120€</a>', ]; $('#message').hide(); nextMsg(0); </script></div></div>
1 回答

莫回無
TA貢獻1865條經驗 獲得超7個贊
實際上,我認為你指的是方法setInterval。我相信你應該使用一個初始值為1的計數器。每次調用interval方法后,計數器應該增加1,然后你可以檢查計數器是否超過了值60,然后才進行ajax調用并重新啟動everythink 。
它應該看起來像這樣
var counter = 1;
var timer = 0;
yourAjaxCall();
var t = setInterval(function(){
//do client side stuff with time
//after you done check if time needs to be fetched from server {60 seconds passed}
counter++;
if(counter >= 60){
counter = 1;
yourAjaxCall();
}
}, 1000);
function yourAjaxCall(){
$.ajax({
url: 'yoururl',
type: 'post',
success: function(response){
timer = response;
}
});
}
添加回答
舉報
0/150
提交
取消