admin管理员组

文章数量:1302360

I try to create a floating menu like Aloha editor but it not working properly. Any one can help me with basic example for floating menu in jquery.

I am not looking for menu floating I need similar toolbar floating in Aloha editor

$(document).ready(function() {
            var fBox = $('#box');
              fBox.draggable();
              $(".columns").click(function(e){
                var mouseXPos = e.pageX;
                var mouseYPos = e.pageY;
                console.log("mouseXPos:"  + mouseXPos + "cleft:" +mouseYPos);
              fBox.animate({top:mouseYPos},1000);
              fBox.animate({left:mouseXPos},1000);
              });
            });

CSS

<style>
        #page{width:600px;margin:0 auto;}
        #page .columns{float:left;width:250px;}
        #box{   background-color: #FFFFFF;
    border: 1px solid #CCCCCC;
    left: 749px;
    opacity: 0.9;
    padding: 0 10px;
    position: absolute;
    top: 35px;
    width: 216px;}
        </style>

HTML

<div id="page">
            <div class="columns">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            </div>
            <div class="columns">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            </div>
            <div id="box">
                <h2>hello world</h2>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
            </div>
        </div>

example floating toolbar /

I try to create a floating menu like Aloha editor but it not working properly. Any one can help me with basic example for floating menu in jquery.

I am not looking for menu floating I need similar toolbar floating in Aloha editor

$(document).ready(function() {
            var fBox = $('#box');
              fBox.draggable();
              $(".columns").click(function(e){
                var mouseXPos = e.pageX;
                var mouseYPos = e.pageY;
                console.log("mouseXPos:"  + mouseXPos + "cleft:" +mouseYPos);
              fBox.animate({top:mouseYPos},1000);
              fBox.animate({left:mouseXPos},1000);
              });
            });

CSS

<style>
        #page{width:600px;margin:0 auto;}
        #page .columns{float:left;width:250px;}
        #box{   background-color: #FFFFFF;
    border: 1px solid #CCCCCC;
    left: 749px;
    opacity: 0.9;
    padding: 0 10px;
    position: absolute;
    top: 35px;
    width: 216px;}
        </style>

HTML

<div id="page">
            <div class="columns">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            </div>
            <div class="columns">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            </div>
            <div id="box">
                <h2>hello world</h2>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
            </div>
        </div>

example floating toolbar http://elankeeran./manish/prototype/alohaEditor/

Share edited May 21, 2011 at 9:41 Elankeeran asked May 21, 2011 at 7:57 ElankeeranElankeeran 6,1849 gold badges42 silver badges57 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 3

There is a tutorial here:

Creating a Floating HTML Menu Using jQuery and CSS

I wanted to do the same and I found a great tutorial here!

You can just use CSS, and give the menu a style of position:fixed

Just be aware this won't work on Internet Explorer 6. For internet explorer you can then use jQuery to reposition the item. Use a conditional tag to include a stylesheet that sets your menu to position:absolute and then use something like the snipped below to move your div, when the window is scrolled:

$(window).scroll(function() {
   $('#myElement').css('top', $(this).scrollTop() + "px");
});

Be aware that the scroll listener fires a lot, so you may want to throttle it to negate any performance issues. For more on that see John Resigs blog post here.

You might want to see Toolbar.js. It creates a tooltip like toolbar in which you can add various control. It's really nice looking and very customizable.

Toolbar.js - A jQuery Plugin To Create Responsive Tooltip Style Toolbars

本文标签: javascriptFloating menu toolbar in jqueryStack Overflow