Shifting a div element using Jquery towards the left side

Hey there, I'm new to this web design thing and I recently tried creating my own website. I stumbled upon a fantastic Slider Menu on this website: http://tympanus.net/codrops/2010/06/28/awesome-cufonized-fly-out-menu/

The only issue I'm facing is that with my limited knowledge of jQuery, I can't figure out how to make the menu slide from the right side to the left side instead of its current left to right motion.

I've tried various solutions mentioned in this forum, but none seem to be working for me.

This snippet shows the code from my index.html file:

<script type="text/javascript>
        $(function() {
            Cufon.replace('a, span').CSS.ready(function() {
                // Code for the sliding menu goes here 
             }) ;
        });
    </script>

And here's an excerpt from my style.css file:

.slidingMenu {
position: absolute;
height:410px;
width: 410px;
top:200px;
overflow:hidden;
font-family: Arial, Helvetica, sans-serif;
}
// CSS styling for the sliding menu continues further down

I did try adjusting the 'right:0px;' attribute in the .slidingMenu class which did center the menu, but unfortunately, the slides still originate from the left side rather than the right.

If anyone has any suggestions or tips on how to make this work, I would greatly appreciate it!

Answer №1

Are you looking for this solution? It took me a long time to make it work, but here is how your HTML page should look:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>Amazing Cufonized Fly Out Menu with jQuery and CSS3</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="description" content="Amazing Cufonized Fly Out Menu with jQuery and CSS3" />
        <meta name="keywords" content="cufon, jquery, css3, menu, navigation, slide out, fly out, hover"/>
        <link rel="stylesheet" href="css/style.css" type="text/css" media="screen">

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script src="cufon-yui.js" type="text/javascript"></script>
        <script src="BabelSans_500.font.js" type="text/javascript"></script>
        <script src="jquery.easing.1.3.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                Cufon.replace('a, span').CSS.ready(function() {
                    var $menu       = $("#slidingMenu");

                    /**
                    * the first item in the menu, 
                    * which is selected by default
                    */
                    var $selected   = $menu.find('li:first');

                    /**
                    * this is the absolute element,
                    * that is going to move across the menu items
                    * it has the width of the selected item
                    * and the top is the distance from the item to the top
                    */
                    var $moving     = $('<li />',{
                        className   : 'move',
                        top         : $selected[0].offsetTop + 'px',
                        width       : $selected[0].offsetWidth + 'px'
                    });

                    /**
                    * each sliding div (descriptions) will have the same top
                    * as the corresponding item in the menu
                    */
                    $('#slidingMenuDesc > div').each(function(i){
                        var $this = $(this);
                        $this.css('top',$menu.find('li:nth-child('+parseInt(i+2)+')')[0].offsetTop + 'px');
                    });

                    /**
                    * append the absolute div to the menu;
                    * when we mouse out from the menu 
                    * the absolute div moves to the top (like initially);
                    * when hovering the items of the menu, we move it to its position 
                    */
                    $menu.bind('mouseleave',function(){
                            moveTo($selected,400);
                          })
                         .append($moving)
                         .find('li')
                         .not('.move')
                         .bind('mouseenter',function(){
                            var $this = $(this);
                            var offsetLeft = $this.offset().left - 20;
                            //slide in the description
                            $('#slidingMenuDesc > div:nth-child('+ parseInt($this.index()) +')').stop(true).animate({'width':offsetLeft+'px'},400, 'easeOutExpo');
                            //move the absolute div to this item
                            moveTo($this,400);
                          })
                          .bind('mouseleave',function(){
                            var $this = $(this);
                            var offsetLeft = $this.offset().left - 20;
                            //slide out the description
                            $('#slidingMenuDesc > div:nth-child('+ parseInt($this.index()) +')').stop(true).animate({'width':'0px'},400, 'easeOutExpo');
                          });;

                    /**
                    * moves the absolute div, 
                    * with a certain speed, 
                    * to the position of $elem
                    */
                    function moveTo($elem,speed){
                        $moving.stop(true).animate({
                            top     : $elem[0].offsetTop + 'px',
                            width   : $elem[0].offsetWidth + 'px'
                        }, speed, 'easeOutExpo');
                    }
                }) ;
            });
        </script>
        <style>
          span.reference{
              position:fixed;
              left:10px;
              bottom:10px;
              font-size:14px;
          }
          span.reference a{
              color:#aaa;
              text-decoration:none;
          }
        </style>
    </head>
    <body>

        <div>
            <span class="reference">
                <a href="http://tympanus.net/codrops/2010/06/28/amazing-cufonized-fly-out-menu/">back to hello</a>
            </span>
        </div>

        <div id="slidingMenuDesc" class="slidingMenuDesc">
           <div><span>hello1</span></div>
            <div><span>hello2</span></div>
            <div><span>hello</span></div>

        </div>



    <ul id="slidingMenu" class="slidingMenu"> 
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li> 
        <li><a href="#">4</a></li> </ul>
        </ul>


    </body>
</html>

Note: Don't forget to properly source your scripts.

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

OnePageCheckout may result in empty boxes being displayed due to OneStepCheckout CSS styling

Seeking advice for an issue with the Magento OneStepCheckout module. Upon checkout, there are three columns: customer data (working fine), payment options (selectable via checkbox), and details about the chosen payment method. Unfortunately, the informati ...

I am encountering difficulties with generating images on canvas within an Angular environment

I am trying to crop a part of a video that is being played after the user clicks on it. However, I am encountering the following error: ERROR DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may no ...

Verify the presence of the input post in the mongo database

Currently, I am utilizing the following node js code to store data in a database... //connect to database db.on('error', console.error); db.once('open', function() { router.post('/register', function(request, response) { ...

having trouble with npm installation of firebase-tools

I am encountering an issue while attempting to set up firebase-tools for my android studio project. Here is the error message that I am facing: Microsoft Windows [Version 10.0.15063] (c) 2017 Microsoft Corporation. All rights reserved. C:\WINDOWS&bs ...

Automatically Populate list upon webpage initialization - React, Redux, Firebase

A webpage I am working on consists of two main components: Categories and Items By utilizing the function initCategories() called within the componentDidMount() lifecycle method of Categories, I successfully display all categories on the screen. The initC ...

Tips for displaying a navbar dropdown menu outside of its container

Before encountering this issue, I was struggling with making the navbar scroll on smaller screens when expanded. I found a helpful solution on Stack Overflow: responsive fixed-top navbar when expanded fills up screen, hides some of the nav-links, and does ...

Create a Vue3 Component without attaching it to the DOM

Let's consider creating a Vue3 component in the following way: import { defineComponent } from "vue"; var instance = defineComponent({ computed:{ message() { return 'Hello world' } } }) To instantiate it and ...

Add a line break in JavaScript to split a string at every 12 characters, while accounting for HTML tags

I am facing a challenge with handling strings that contain multiple smaller strings wrapped in HTML tags. My goal is to insert a line break after every 12 characters, excluding the tags themselves. '<span>This is a text.</span><span> ...

Is there a way to submit the value of a textbox that has been generated dynamically using jQuery?

I am currently using the CodeIgniter framework and am attempting to incorporate textboxes in an HTML form. When the user clicks a button, a new textbox should be generated automatically using jQuery. However, when I submit the form, the values of the dynam ...

What is the best way to create a two-tiered bootstrap navigation bar?

I am trying to create a similar design in Bootstrap. https://i.sstatic.net/uby64.png If you have any advice or know of a plugin that could assist me with this, I would greatly appreciate it. The original design was created in Justinmind. Thank you in ad ...

All You Need to Know About Jquery's Selector for Nested Elements

Could someone clarify if the Jquery Statement $(selecterA:not(selectorB), elementA) means "return those elements that match selectorA but not selectorB within elementA"? I am confused by a simple case in Fiddle#1, where both output statements using .length ...

To properly handle this file type in React, ensure you have the correct babel loader installed

https://i.sstatic.net/iNFs3.pngAn error is triggered when trying to compile with webpack. The message indicates that an appropriate loader may be needed to handle this file type. The libraries I am using are: https://i.sstatic.net/a8fXR.png Below are my ...

The loading of jQuery AJAX is restricted within the <select> tag

<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".region").load('getRecords.php?start=regions'); }); </script> </hea ...

Developing a Generic API Invocation Function

I'm currently working on a function that has the capability to call multiple APIs while providing strong typing for each parameter: api - which represents the name of the API, route - the specific route within the 'api', and params - a JSON ...

Customize the date format of the Datepicker in Angular by implementing a personalized pipe

I am dealing with a datepicker that defaults to the MM/dd/yyyy format, and I need it to adjust based on the user's browser language. For example, if the browser language is English India, then the format should be set to dd/MM/yyyy as shown below. Be ...

Can the rgb color selection feature be utilized in the $mdThemingProvider?

Currently, I am in the process of developing a Firefox OS application using angularjs and angular-material. One feature that I would like to incorporate is allowing users to customize the colors of their app. To achieve this, I have utilized the md-slider ...

When the ngFor data reaches a count of four, it will be shown in a separate container div

I am struggling to find a way to display my ngFor data in a new container div once the length reaches four. It's easier to hard code the data into separate divs, but using ngFor results in the data being displayed in a single container div. In the co ...

Creating a CSS design where the border is contained within an element, especially when the border radius is specified

The concept of the title might be a bit confusing, but let me clarify. I am attempting to replicate this particular effect (taken from a .png file): This is essentially half a cycle with a black line inside it. Despite numerous attempts, I have been un ...

Adding a space after an attribute in HTML5 is crucial for proper

I remember reading that in XHTML, it was recommended to have a space between attributes and the closing bracket of a tag. For example, <a href="example.com" > instead of <a href="example.com">. I'm curious if this also applies to HTML5, an ...

"Exploring the world of two-dimensional arrays and enhancing user

My goal is to create a form that contains a list of products. When the user starts typing the product name, an autocomplete feature should display available options based on the product names (first array element). If the user selects a product, the pric ...