Nov 21, 2009

Expandable Div Width With Dynamic Items

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > HTML, XML etc..

Expandable Div Width With Dynamic Items

sonesay
Does anyone know how to create this?

1. The Div will be a fix height.
2. The Div will be auto expanding with a minimum width of 600px
3. The Div will show items depending on the amount of width available.

The other requirements like navigating buttons are not as important as the expanding and changing amount of items being displayed at this stage. I will try and get those done once the first 3 requirements are meet.

Any links or suggestions on how to go about this appreciated.

Cheers
Sone

Comment/Reply (w/o sign-up)

jlhaslip
Will there be a minimum of the three Images as per your Sample up there? Or are those div's of text?
Looks to me like a javascript solution to supply the left and right arrow scroll markers.
Because IE will not recognize the min-width element is CSS, that will require an IE conditional comment to supply certain CSS to it.

Google javascript scrollers and see what you come up with.
*edit*
Found this one http://jqueryfordesigners.com/demo/slider-gallery.html
It uses a slider instead of the Arrow head images you have shown.

Comment/Reply (w/o sign-up)

sonesay
Thanks for the link jlhaslip. Unfortunately that is not exactly what I'm after. I need the outer most containing Div to be dynamic in width. The items inside them will be thumb nails and maybe also text including descriptions.

Comment/Reply (w/o sign-up)

truefusion
I came up with something that does pretty much what you want. The only problem is getting it to look nice inside the container; that is, centering the objects or distributing them evenly. For that, i'll just leave it to you. tongue.gif And by the way, this script uses JQuery, so you'll need to download that and edit the code to include that version of JQuery.

HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Slider test</title>
<script type="text/javascript" src="/ajax/jquery-1.2.6.pack.js"></script>
<style type="text/css">
#sliderContainer {
padding: 3px;
border: 1px solid black;
height: 250px;
}

#sliderContainer button {
height: 250px;
}

#sliderArea {
overflow: hidden;
height: 250px;
margin-left: 3px;
margin-right: 3px;
}

#sliderArea ul {
list-style: none;
white-space: nowrap;
margin: 0;
padding: 0;
}

#sliderArea ul li {
display: inline;
}

#sliderArea ul li > div {
padding: 3px;
border: 1px solid black;
width: 600px;
height: 242px;
float: left;
}

.hidden {
display: none;
}
</style>
<script type="text/javascript">
//<![CDATA[

var index = 0;
var children;
var parentWidth;
var childWidth;
var visChildren;

$(document).ready(
function(){
children = $("div#sliderArea ul li").children("div");
parentWidth = $("div#sliderArea").width();
childWidth = $(children[0]).width();
visChildren = Math.floor(parentWidth/childWidth);
}
);

function prev()
{
index = index - 1;
if (index < 0){
index = 0;
}
$(children[index]).removeClass("hidden");
}

function next()
{
//if (index < (children.length-1))
if (index < (children.length-visChildren))
{
$(children[index]).addClass("hidden");
index = index + 1;
}
}

//]]>
</script>
</head>
<body>

<div id="sliderContainer">
<button style="float: left;" onclick="prev();">&laquo;</button>
<button style="float: right;" onclick="next();">&raquo;</button>

<div id="sliderArea">
<ul>
<li><div>1</div></li>
<li><div>2</div></li>
<li><div>3</div></li>
<li><div>4</div></li>
<li><div>5</div></li>
<li><div>6</div></li>
</ul>
</div>

</div>

</body>
</html>

 

 

 


Comment/Reply (w/o sign-up)

sonesay
Thanks again for the excellent code truefusion. This seems to work perfectly on its own but as I try and integrate it into my existing site it reports function undefined errors under firebug. This could be of course my own fault but I've tried including the jquery file in the header and also just in the body before the acutual slide show begins.

I am beginning to suspect it may have something to do with my other included .js files in the header conflicting? I have an idea I will try remove them and see how it goes.

example of problem and one working fine at this stage.
http://sonesayi.com/si/
http://sonesayi.com/si/slideshow.html



update 9.19pm NZL Time 24/01/2009

I have checked and taken some screen shoots to confirm that does appear to be conflicts with the 3 scripts

CODE
<script type=\"text/javascript\" src=\"js/prototype.js\"></script>
<script type=\"text/javascript\" src=\"js/scriptaculous.js?load=effects,builder\"></script>
<script type=\"text/javascript\" src=\"js/lightbox.js\"></script>


When I comment these out there is no error and the page functions fine. Now I'm at a loss at to what to do right at this time. Any ideas welcome ^^


update 11.10pm NZL Time 24/01/2009

fixed js conflicted. change functions prev, next to prevItem, nextItem (conflict with next function somewhere).
jQuery.noConflict();

Comment/Reply (w/o sign-up)

sonesay
Just a question concerning how its structured. You've used an unordered list for the containers of Div's. Does this help in keeping them displayed inline? I am having trouble trying to find a way to center them. I have tried to apply text-align: center for the container div "slideArea" but still no effect. I can live with not being able to center them nicely but it would be nicer looking centered smile.gif

you can see it at http://sonesayi.com/si

Comment/Reply (w/o sign-up)

truefusion
QUOTE (sonesay @ Jan 24 2009, 06:59 PM) *
You've used an unordered list for the containers of Div's. Does this help in keeping them displayed inline? I am having trouble trying to find a way to center them.

Yeah, the inline list items is what made it possible to actually work with the block-level divisions. I had and have an idea on how to center or distribute the list items evenly, which includes margins and another math equation. I'll include the code when i implement it.
CODE
<script type="text/javascript">
//<![CDATA[

var index = 0;
var children;
var parentWidth;
var parentPadding;
var childWidth;
var visChildren;

$(document).ready(
function(){
children = $("div#sliderArea ul li").children("div");
parentWidth = $("div#sliderArea").width();
parentPadding = $("div#sliderArea").css("margin-left");
childWidth = $(children[0]).width();
visChildren = Math.floor(parentWidth/childWidth);
distribute();
}
);

function prevItem()
{
index = index - 1;
if (index < 0){
index = 0;
}
$(children[index]).removeClass("hidden");
distribute();
}

function nextItem()
{
if (index < (children.length-visChildren))
{
$(children[index]).addClass("hidden");
index = index + 1;
}
distribute();
}

function distribute()
{
var margin = parentWidth - (childWidth * visChildren);
margin = margin/(2*visChildren);
margin -= parseInt(parentPadding)*2;

for (var i = 0; i < children.length; i++){
$(children[i]).css("margin", "0");
}

for (var i = index; i < (index+visChildren+1); i++){
$(children[i]).css({"margin-left" : margin, "margin-right" : margin});
}
}

//]]>
</script>

This code evenly and dynamically (as best as it can) distributes the items.

Comment/Reply (w/o sign-up)

(G)

I have a horizontal navigation,I need that it should dynamically adjust its width according to the number of links.As if it would have 10 links it will be taking the complete area of its div ,and also if one link is added or deleted from it ,it will take the same area[spread out throughout its parent div]How is this possible.Please reply..Its urgent.


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords :

  1. Dynamic Forms Help - How Do I Create These?
    (8)
  2. How To Make Cms For My Dynamic Website?
    A Content Management System (3)
    It is a pain trying to have to write new code everytime you want to change something on my website.
    I know there is an easier way to update content. I read about COntent Management systems which
    apparently use XML. When I would enter the administartion area there woudl be dynamic fileds in
    which I could edit the data and when I click submit it would change. The thing is that I know how
    to add these forms to a page but I dont know how to create an adminstration area. I use php and one
    of my friends said to use XML. I have a book but it is taking a long time to read.....
  3. Width Of Display Area Of Browser Window
    is there a formula? (6)
    I am making a table in a website that's as big as the display area of the browser for instance:
    CODE .... ..... How do I know the width of the browser display area? Better yet, is
    there a general formula for that for other screen resolutions? I know a little bit of javascript,
    are there functions for that?....
  4. Dynamic Button Size
    (1)
    In my application I have a custom tag that generates all the action buttons that the page needs. My
    problem is that in IE the space between the left side of the button and the image inside the button
    are not consistant. Some buttons have 3 or 4 more pixels of padding on the left side then others.
    This causes my buttons to be too large and hence the area the buttons are generated in stretches too
    far. I could wrap the buttons around to another line or add scroll bars.. but if it will fit in FF I
    think it should fit in IE as well. So my question is can I set the padding....
  5. Ie Table Width In A Div Tag
    Table expands past screen at 100% (5)
    Hey everyone. I have been designing websites for a long time but i have recently decided to tryout
    the DIV layout technique instead of just using good old tables. However, this is the biggest problem
    i have come across. So I have a page where i need to have a table to display a whole bunch of
    details on armor in a game since the site is for players of final fantasy. However, when i do
    width="100%" so that the table expands the whole way to the side of the div so it looks the best it
    now will go past the edge and off the screen at 100%. Below is most of the code. Please h....
  6. Dynamic Drop Down Lists
    (0)
    I've got 3 drop down lists. The first one changes what appears in the second two. For some
    reason the code below is only deciding to show me the first two items that appear in the two drop
    down lists in question. So, this leads me to believe the problem shuld be quite simple to solve! but
    i've been stuck on it for a couple of hours now! If someone could help me out here I'd be
    extremely extremely greatful!!!! CODE --Please select-- test product1 // Dynamic
    product sizes + colours var supported = (window.Option) ? 1 : 0; if (supported) { v....
  7. Dynamic Links
    (3)
    his may be a CSS question, but it's the XHTML not validating that's giving me a problem.
    I'm working with the most out-dated shopping cart software (Click Cart Pro) ever and I'm
    trying to get it to validate XHTML 1.0 Transitional. All the XHTML I've supplied is good and
    validates fine, but where I'm falling short at the moment is with the linking. ClickCart Pro -
    by default - spits out HTML from 1996, and the links are supplied with ampersands - not the XHTML
    character entity "&". Par l'exemple: Code: CODE I'm wondering i....
  8. Max Table Width
    (13)
    Well, I have a table that I don't want to be over 350 pixels in width - even on the largest
    screens. On small screens, the table will be smaller. But on large screens, I don't want the
    table to larger than 350 pixels... Is there a way to do that?....
  9. Table Width Help
    table width="100%" goes off screen (2)
    Hey everyone. My problem is that current i have a left menu and a right menu which are created using
    a div the properties listed below. Then i have a center section to my website where i have a table
    that i need to fill the remaining space on the screen (aka the space from the right side of the left
    menu to the left side of the right menu). However, when i set the table's width to 100%, it goes
    of the screen. Can anyone help me with this? If you look at my main page, the news section works but
    only because the text forces the table to its largest size and then wraps.....
  10. Popup Window With Height And Width?
    (10)
    I will try to explain: When clicking on the link, a pop-up window will be opened. I also want to
    have the width=300 and height=160 (just examples /wink.gif' border='0'
    style='vertical-align:middle' alt='wink.gif' /> ) Could someone give me a short code for that?....
  11. Adding Width And Height To Page
    (8)
    how do you add width and height to your page? without adding it to your link you previously
    clicked... I mean, that the width and height should be included in the ORIGINAL page... i hope
    someone can help me with this... thanks in advance! /cool.gif' border='0'
    style='vertical-align:middle' alt='cool.gif' /> btw: i'm not that familiar with
    scripting.......
  12. "dynamic Instance"
    (0)
    My problem is the following: I work disconnected (no asp nor php etc...), with formsplayer What I
    want to do is to change dynamically (script javascript) the source of the model instance. I thougth
    about Something like: .... ChangeModelInstance(); function ChangeModelInstance() { var
    theModel = document.getElementById("myModel"); var theInstance =
    document.getInstanceElement("myData"); //... //Change source to page2.xml //... theModel.refresh();
    } Change instance source But I didn't manage to do it does anyone have an idea?
    thank in advan....

    1. Looking for Expandable, Div, Width, With, Dynamic, Items

Searching Video's for Expandable, Div, Width, With, Dynamic, Items
See Also,
advertisement


Expandable Div Width With Dynamic Items

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com