English 中文(简体)
jquery记住上页后消沉的情况
原标题:jquery remember state of animation after page reload

I have a block following my menu buttons, to indicate which one is active. Is there a way to keep the block s location after a refresh? As of now the location gets reseted when I press a link in a subpage.

jquery Code:

$( "button",document.body ).click(function(){
    var offset = $(this).offset();
    var offsetBody = $("body").offset();
  $( "#block" )
     .animate({
    left: (offset.left - offsetBody.left) 
  }, 200);
});
最佳回答

Jquery是客户方的文字。 当你将一页或一页重新上载到新网页时,请服务器提供信息,这意味着所有客户方的数据都丢失。

然而,根据你的确切问题,有一些解决办法。

  1. 如果你只关心每一页的栏目的位置,那么你就可以将标记中的某些内容编码为具有相当于某种特性的属性价值,在装货时检查这一价值,并相应地搬走。

  2. 你可以使用客户方的厨师储存价值,并在人力部装货时核对这一变数,并相应地对块进行清点。

  3. 你们可以使用非洲宇宙航空研究开发机构的呼吁,在PHP中设定一个服务器方变量,并利用这一变量动态地在1中形成要素。

你是否认为这三项解决办法有任何工作? 如果你能够更确切地告诉我,你将如何做到这一点,我可以更详细。

方法1

使用J Query

标记

<meta name="description" content="home" />

J Query

var page = $( meta[name=description] ).attr("content");
if (page == "home") {
    // you know where it should be
} else if (page == "account") {
    // you know where it should be
}

然而,我略感担心的是,这究竟是不是你想要的。

方法3

标记

<?php
    session_start();
    $pos = $_SESSION[ position ];
    echo  <meta name="description" content="  . $pos .  " /> 
?>

J Query

var position;
// perform animation stuff and store position in the variable
// make a post() request after the position has changed
$.post("position.php", { pos: position } );

PHP职位。 php

<?php
    session_start();
    $_SESSION[ position ] = $_POST[ pos ];
?>
问题回答

You can store the position in the following object. 1. Local storage(browser support) In the modern browsers, you can store the position in Localstorage. pros:fast, user friendly. cons:you need to handle the cross browser. 2. Server side. Otherwise, you need to store it in the serverside() pros:No need to take browsers into account. cons:Slow, you need to concern internet latency. 3. Cookies.





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签