---
title: "Fancybox update() function reseting my scroll"  
description: "Fancybox update() function reseting my scroll"  
author: "Anonymous User"  
published: 2014-11-24  
updated: 2014-11-25  
canonical: https://www.mindstick.com/forum/12683/fancybox-update-function-reseting-my-scroll  
category: "javascript"  
tags: ["jquery", "html"]  
reading_time: 2 minutes  

---

# Fancybox update() function reseting my scroll

I have a fancybox popup in which I have [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) accordions. So the size of the popup varies on clicking of these accordions. Each of the [accordion](https://www.mindstick.com/blog/626/accordion-using-bootstrap-in-asp-dot-net) is an [anchor tag](https://www.mindstick.com/forum/156201/what-is-the-use-of-anchor-tag-in-seo).

On expanding one or more accordions, there is a limit(max-height) to which my popup will [expand](https://www.mindstick.com/articles/13054/here-s-how-crm-can-help-you-expand-your-business), after which the [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) inside the popup becomes scrollable, [i.e](https://answers.mindstick.com/qa/39877/what-state-was-the-first-to-enter-the-union-i-e-was-the-first-to-ratify-the-united-states-constitution), the content inside the div with [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) .fancybox-inner .

Whenever an accordion is clicked I call $.fancybox.update() as the popup need to be re-sized and respositioned.

But $.fancybox.update() resets the current scroll position of the content inside popup.

So i made this [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) adjustPopup and call it when any of the accordion is clicked

```
function adjustPopup(target) {    var fancyboxInner = $('.fancybox-inner')[0],         scrollTop = fancyboxInner.scrollTop;     //$.fancybox.update() function resets the vertical scroll of fancybox popup, so we store the    //scrollTop before calling $.fancybox.update() and then assign it back when updated.    $.fancybox.update();    fancyboxInner.scrollTop = scrollTop;}
```

But this doesn't work. Even though i set the proper scrollTop [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) its again reset to 0 somehow. Does [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) know whats the issue here?

## Replies

### Reply by Anonymous User

I found the solution. I had to dig into $.fancybox.update() function where I found that this function does stuff asynchronously. So my scroll was getting reset even though I was setting the scroll right after calling update.

I realized that there is an event 'onUpdate' on which the update is actually completed.

**So I modified my adjustPopup function to this:**

```
function adjustPopup(target) {    var fancyboxInner =$('.fancybox-inner')[0],         scrollTop =fancyboxInner.scrollTop;    //$.fancybox.update()
function resets the vertical scroll of fancybox popup, so we store the    //scrollTop before calling $.fancybox.update() and then assign it back when updated.    $.fancybox.one('onUpdate',function() {        fancyboxInner.scrollTop= scrollTop;    });    $.fancybox.update();}
```


---

Original Source: https://www.mindstick.com/forum/12683/fancybox-update-function-reseting-my-scroll

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
