Difficulties with the Slide Page

Need help figuring this out? I'm attempting to implement a page slide method from this

http://jsfiddle.net/XNnHC/942/

$(document).ready(function()
{
    var slider_width = $('.pollSlider').width();//automatically get width
  $('#pollSlider-button').click(function() {
    if($(this).css("margin-right") == slider_width+"px" && !$(this).is(':animated'))
    {
        $('.pollSlider,#pollSlider-button').animate({"margin-right": '-='+slider_width});
    }
    else
    {
    if(!$(this).is(':animated'))//prevent double click to double margin
        {
            $('.pollSlider,#pollSlider-button').animate({"margin-right": '+='+slider_width});
        }
    }


  });
 }); 

I have been trying with this approach:

http://jsfiddle.net/ejkim2000/f7DVK/

But I've encountered some issues.

The first problem is the trigger button place receiving a margin, causing the text after place to be displaced. I removed #pollSlider-button in this piece of code:

$('.pollSlider,#pollSlider-button').animate({"margin-right": '-='+slider_width}); }

To remove the margin from the button but ended up with the sliding page continuing to move right. Is there a way to make the sliding page work without adding margin to the button?

Another issue is that I added another button on the slide page for closing action, but it doesn't seem to work and I can't figure out why. Hopefully, someone can assist in making this closing button functional.

Just an FYI, I prefer using width and height with CSS for ease in creating a responsive slide page and I would like to extend this method to other directions as well.

Thank you!

Answer №1

Give this a try

Effective Solution: DEMO1

This method uses the same button to close and open the slider.

$(document).ready(function () {
    var slider_width = $('.pollSlider').width(); 
    $('#pollSlider-button').click(function () {
        if ($('.pollSlider').css("margin-right") == 0 + "px") {
            $('.pollSlider').animate({
                "margin-right": '-=' + slider_width
            });
        } else {

            $('.pollSlider').animate({
                "margin-right": '+=' + slider_width
            });

        }
    });
});

Take a look at this example as well:

Another Approach: DEMO2

This method involves using separate buttons for opening and closing the slider.

$(document).ready(function () {
    var slider_width = $('.pollSlider').width();
    $('#pollSlider-button').click(function () {   
        if ($('.pollSlider').css("margin-right") == "-" + slider_width + "px") {
            $('.pollSlider').animate({
                "margin-right": '+=' + slider_width
            });
        }
    });

    $('#pollSlider-button2').click(function () {  
        if ($('.pollSlider').css("margin-right") == 0 + "px") {
            $('.pollSlider').animate({
                "margin-right": '-=' + slider_width
            });
        }
    });

});

I hope these solutions are helpful. Thank you!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I make my div disappear when I click outside of it using jQuery? I am finding the solution on Stack Overflow to be confusing

Utilizing jQuery to conceal a DIV upon clicking outside of it Although I've heard positive feedback about this method, I'm uncertain about its functionality. Can someone provide an explanation? I understand that .has() identifies elements contai ...

Is there potentially a memory leak in this code? If there is, what steps can be taken to eliminate it?

Recently I inherited a project from my senior colleagues that focused on seamless page reloading using AJAX. The code is filled with numerous functions like this one: function iCreateProblems() { //some random code document.getElement ...

Including jQuery in an Angular project generated with JHipster

I am facing a challenge with integrating jQuery into my Jhipster Angular project as a newcomer to Jhipster and Angular. My goal is to customize the theme and appearance of the default Jhipster application, so I obtained a theme that uses a combination of ...

Click on the dropdown item in the Bootstrap btn-group dropdown

I am interested in clicking the dropdown item within the btn-group and triggering an alert message. This is the HTML code I have: <td> <div class="btn-group" role="group"> <button id="btnGroupVerticalDrop2" type="button" class= ...

Is there a PHP equivalent of a jQuery-style interface available?

Is there a PHP library available that offers a jQuery-style interface for working with HTML/XML files, particularly using jQuery-style selectors? I am interested in performing tasks like the following examples (purely hypothetical): foreach (j("div > ...

Create dynamic and interactive content by embedding text within SVG shapes using the powerful D

How can I write text into an SVG shape created with d3.js and limit it to stay inside the shape similar to this example http://bl.ocks.org/mbostock/4063582? I attempted to use a clipPath following the example provided. However, when inspecting with firebu ...

I'm having trouble displaying the result of my calculation in the code. Could it be because I forgot to include an output tag?

I am attempting to develop a Miles Per Gallon (MPG) calculator using Javascript. However, I'm encountering difficulties with displaying the results once the "Calculate" button is pressed. <html> <head> <title> MPG Calculator </ti ...

Tips for transferring variables to my callback function or something similar

I'm facing a challenge with passing the markersArray to the callback function in order to push the results into the relevant array. The issue arises when trying to request nearby amenities for each filter and store them in separate arrays as per the c ...

An issue arises when attempting to send form information through email using PHP

I'm facing an issue with sending email from a form. Every time I submit the form, I receive an "error occurred" message as specified in my if else statement. This prevents the mail from being sent. Can you help me troubleshoot this problem? Below is t ...

Storing image data using JavaScript

I am in the process of creating a 360-degree viewer that utilizes raster tiles (leaflet) and requires over 85,000 images for each view. In order to enhance the viewer's performance, I am attempting to cache all of these images. However, I keep receivi ...

Selecting Bar Graphs with Highlighting and Un-Highlighting

Is there a way to unhighlight specific highlighted bars while keeping others highlighted in this code that enables multiple bar selection through highlighting? $(function() { var cos = []; for (var i = 0; i < 10; i += 1) { cos.push([i ...

What is the best way to eliminate the header and side navigation in a master page design?

I've set up a master page called wrap.master which is connected to multiple content pages. I'm looking to create a new content page and link it to the master page. However, I want this new content page to be independent from the header and side n ...

How to activate a jQuery event with a click trigger

$('#content #home nav #navigationList li:nth-child(2) a').trigger("click"); $('#content #home nav #navigationList li:nth-child(2) a').css("background", "red"); I am facing an issue with creating an event trigger click on an element. ...

Is your Javascript navigation functioning properly on some submenus while encountering issues on others?

If you visit , you'll notice that it's a visually appealing site. The navigation submenus seem to be functioning properly, HOWEVER upon inspecting the element, you'll notice that under the PRICING tab, there are submenus that have the same c ...

Merge the xAxis functionality with Highcharts

My issue involves a chart generated by highcharts.js. The problem arises with a line chart consisting of 5 values (5 points), each displayed on the xAxis as follows: from value 1 to value 2: 0, 0.25, 0.5, 0.75, 1. I am looking to modify this display and re ...

Top method to generate animated hotspots and image maps

After scouring the internet for hours, I was disappointed by the lack of helpful information on this particular topic. Perhaps my search terms were not as effective as they could have been. This leads me to my question: What is the most effective way to c ...

Encountering an issue with Firebase authentication in Next.js: the window object is not defined

Here is some code snippets: import { initializeApp } from "firebase/app"; import { getAnalytics } from "firebase/analytics"; import { getAuth } from "firebase/auth"; const firebaseConfig = { //credentials// }; export const ...

"Incorporating input boxes for MySQL updates using PHP, MySQL, and HTML

I'm looking to make my input box dynamic, where it can read the current value from the database and allow users to change that value. Currently, when I enter a number like 1000 into the input box, it posts fine. The PHP results show: Data updated: c ...

What is the best way to pass a dynamically updated value to the controller?

<form id="participantsForGd"> <span id="GroupID"></span> //example: group id 2 will be displayed here <button id="GdStartTest">Start test</button> </form> I need to pass the value of GroupID to the controller through an ...

What is the most efficient way to loop through an array and send each item to a method, ensuring that all methods are executed synchronously?

I need to make a request method call that retrieves its own body as an array, which is one item within another array. To achieve this, I have to iterate over the parent array and pass each of its items to the request method for a new server request. I tr ...