I can't figure out the ajax issue so I was wondering if I could do something like this:
click to see larger version
The container of the article blocks have a hidden overflow while the article blocks are inline-block. The problem with this is, if I set a width to the container, the blocks would not be inline anymore. They would drop underneath each other instead of hidden off the page. Does this make sense?
@TheDoc Damn. I hope there is a CSS solution as well. Maybe absolute positioning? The only issue I see with your version is that if I increase the width of the blocks, they wrap underneath each other. The reason this can't happen is because I will be using a jQuery click function to slide in the next set of blocks. Much like what I'm doing with ajax in the above link.
@yeeyang If you look above at the image, I want an infinite row of content blocks that has a container of overflow hidden (so it only shows a set of 3 at a time). Then, with an on click function using jQuery, slide in the next 3 blocks. Make sense?
Take a look here: http://chrisburton.me/dev. Click on the arrows. That is what I'm trying to accomplish without ajax since I can't figure out a bug.
I removed the position: relative from your .container and added a div.wrapper around everything and set that up as a position: relative to establish a positioning context. Then kept the position: absolute on your .inner-container, which should snap to it's closest parent positioning context, which is now .wrapper.
Used a bit of jquery to figure out the width and set that up for the style of .inner-container and got your buttons hooked up to animate...
you'll want to tweak it and clean it up but I think that's what you're looking for.
Oh I remember why I had the extra div, you can use this div as a hook for jQuery to apply relative position to. I updated the pen to demonstrate this :)
@CrocoDillon I was talking with @jamy_za privately and I think we came up with a decent solution. I'm going to load in all my articles and use a jQuery Carousel for the functionality. I need to do a few tweaks to make it work exactly how I want it to but here it is: http://chrisburton.me/dev/
@HugoGiraudel Initially I wanted to use Ajax but ran into a minor problem that I personally couldn't solve. Oh and couldn't recall the name of the carousel functionality until @yeeyang pointed it out.
I'm running into one small problem with the carousel. When sliding to the previous items (right arrow), it will load back in the beginning article (see after getting to article 1, it shows 7 and 6 after it). I'd rather it just show the last article (1) and then have to click the left arrow to get back to the beginning. Any ideas?
did you have circular set to false as well? the example at the very bottom of their homepage is what you're looking for functionally. Checkout their javascript call and settings.
@yeeyang Nope, that's actually not what I wanted. I wanted the last item by itself instead of sliding over one. I emailed them and they said it isn't possible currently. I have to use an entirely different plugin which I think I've found.
3 blocks -> (slide) -> 3 blocks -> (slide) -> last block + first 2 blocks
So it slides 3 blocks twice and adds two of the beginning blocks on the last one. This is not ideal nor what I'd like. It's been quite frustrating that I can't seem to find one that doesn't do what I explained in the second example.
I took the liberty to upload the content to CodePen in case anyone would like to help. I also renamed the title.
Ermmm, I haven't thought about that. No attribution needed but if you insist just name will be fine since my website is just a placeholder right now :P
I'm playing with the idea of using % as positioning and it seems to fix that problem, but it adds another. How to know what % to use? left: -100%; translates to 985px, if I'd figure out where this number comes from I could write the code to calculate the exact % to use, instead of what I'm doing here http://codepen.io/CrocoDillon/pen/xmBuA , using multiples of -100%.
@CrocoDillon Perhaps all three widths (320px * 3 = 960) and a margin of the arrow (320px * 3 + 25px = 985px)? Although, I'm not seeing anything rendering 985px. I wonder if wrapping it in another div might help.
Update: I don't want to jump the gun here but using percentages rather than pixels is working when I hard code it into Web Inspector.
For me it doesn't, if I use -100% on #ajax then there is a border visible that shouldn't be visible. Maybe just go with that for now and remove the border for nth-child(3n) again? Or hardcode the 985px in JS (which sucks), I've updated my pen for that. Still an unwanted border though on the 2nd page.
I'm puzzled, let me think about that for a while. Go with the first solution for now? Seems to be the best solution as long as users don't resize after scrolling...
At least I found out where the 985px comes from. jQuery's .position().left gets the position relative to first positioned ancestor (in this case .page-wrap) "Oops" :P That element has 25px padding. So the slider started at 25px relative to that element. Sliding it 100% (or 1010px) to the left made it 985px. At least this isn't a concern anymore, since we aren't setting or getting the #ajax position using that jQuery function. Using the function on the articles worked because #ajax is their positioned ancestor.
So multiples of -100% should work, except it doesn't because the total width of 3 articles is (or should be) 100%, adding borders makes it go over 100%. Using box-sizing: border-box; fixes that. Updated pen: http://codepen.io/CrocoDillon/pen/xmBuA
Can probably cleanup the javascript alot now, a lot vars that aren't needed anymore. (Edit: done)
I don't know, I only tested on CodePen, but yeah that's weird. Maybe what you had were just rounding errors? I did put a few extra decimals to .article { width: 33.3333%; }, and any additional rounding errors get masked with
@CrocoDillon Gotcha. Well, from what I can tell it does work now. Any minor issues I can fix with media queries, I think. Thanks again for taking the time to help me out with this!
To start off, take a look at my current article blocks: http://chrisburton.me/dev
I can't figure out the ajax issue so I was wondering if I could do something like this:
The container of the article blocks have a hidden overflow while the article blocks are inline-block. The problem with this is, if I set a width to the container, the blocks would not be inline anymore. They would drop underneath each other instead of hidden off the page. Does this make sense?
While putting together a pen with a solution that I thought for sure would work, I learned that you can't use
white-space: no-wrap;on block elements.Unfortunately using jQuery to help us out. There must be a pure CSS way that I'm missing, but this can be your fallback!
http://codepen.io/ggilmore/pen/610a62cacbf0c248421e8b3a1e903028
@TheDoc Damn. I hope there is a CSS solution as well. Maybe absolute positioning? The only issue I see with your version is that if I increase the width of the blocks, they wrap underneath each other. The reason this can't happen is because I will be using a jQuery click function to slide in the next set of blocks. Much like what I'm doing with ajax in the above link.
I've been trying with an inner container and absolute positioning..nothing so far
Yeah, it's a tricky request. Thanks @ChrisP and the same to @TheDoc for writing all that up.
Here's what I got. It's kinda hacky with the inner container having a 90000px width, so I guess it's technically not infinite either.
http://codepen.io/ChrisPlz/full/KAqDe
Thanks @ChrisP.
Now I'm trying to slide them but it isn't working that well.
http://codepen.io/chrisburton/pen/BbvyF
Honestly I don't know what you're wanting to achieve... but from my guestimation, you want your articles to be viewable across the entire screen?
Took @chrisburton 's pen and modified it. http://codepen.io/ahabion/pen/bIfvJ
@yeeyang If you look above at the image, I want an infinite row of content blocks that has a container of overflow hidden (so it only shows a set of 3 at a time). Then, with an on click function using jQuery, slide in the next 3 blocks. Make sense?
Take a look here: http://chrisburton.me/dev. Click on the arrows. That is what I'm trying to accomplish without ajax since I can't figure out a bug.
Okay @chrisburton, checkout my pen now.
I removed the
position: relativefrom your.containerand added adiv.wrapperaround everything and set that up as aposition: relativeto establish a positioning context. Then kept theposition: absoluteon your.inner-container, which should snap to it's closest parent positioning context, which is now.wrapper.Used a bit of jquery to figure out the width and set that up for the style of
.inner-containerand got your buttons hooked up to animate...you'll want to tweak it and clean it up but I think that's what you're looking for.
Then again... i think you wanted your content to stay hidden ... doh!
If you're open to a jquery plugin, my recommendation for your usage would be http://caroufredsel.dev7studios.com/
Lots of customizations and will do pretty much anything you want to feed it.
@yeeyang You know what, I think a carousel is just what I need! Thanks.
The non JS solution is to use an extra div between the container and the content blocks, and put the
white-space: nowrapthere.http://codepen.io/CrocoDillon/pen/ifHza
Edit: nevermind, it works without the extra div too... @TheDoc, maybe it didn't work for you because of
no-wrapinstead ofnowrap:POh I remember why I had the extra div, you can use this div as a hook for jQuery to apply relative position to. I updated the pen to demonstrate this :)
@CrocoDillon I was talking with @jamy_za privately and I think we came up with a decent solution. I'm going to load in all my articles and use a jQuery Carousel for the functionality. I need to do a few tweaks to make it work exactly how I want it to but here it is: http://chrisburton.me/dev/
@chrisburton It seems like a no brainer to me. Do not reinvent the wheel. If you are looking for a carousel, just use a carousel.
Looks good :)
@HugoGiraudel Initially I wanted to use Ajax but ran into a minor problem that I personally couldn't solve. Oh and couldn't recall the name of the carousel functionality until @yeeyang pointed it out.
Thanks @CrocoDillon
I'm running into one small problem with the carousel. When sliding to the previous items (right arrow), it will load back in the beginning article (see after getting to article 1, it shows 7 and 6 after it). I'd rather it just show the last article (1) and then have to click the left arrow to get back to the beginning. Any ideas?
Isn't that (looping) the whole point of a carousel?
@CrocoDillon Possibly? Perhaps a content slider might be a better idea?
set your
infiniteto:falseand that should take care of the reload.@yeeyang Didn't work.
did you have
circularset tofalseas well? the example at the very bottom of their homepage is what you're looking for functionally. Checkout their javascript call and settings.@yeeyang Nope, that's actually not what I wanted. I wanted the last item by itself instead of sliding over one. I emailed them and they said it isn't possible currently. I have to use an entirely different plugin which I think I've found.
Would anyone mind helping me create a lightweight content slider from scratch? I can't find one that fits what I need it to do.
Basically I want it to just show 3 articles and slide to the next set. Soo, if I have 7 content blocks, it should do this:
3 blocks -> (slide) -> 3 blocks -> (slide) -> last block
Most content sliders will do this:
3 blocks -> (slide) -> 3 blocks -> (slide) -> last block + first 2 blocks
So it slides 3 blocks twice and adds two of the beginning blocks on the last one. This is not ideal nor what I'd like. It's been quite frustrating that I can't seem to find one that doesn't do what I explained in the second example.
I took the liberty to upload the content to CodePen in case anyone would like to help. I also renamed the title.
http://codepen.io/chrisburton/full/eEwoD
Forked it, could have spend more time styling the arrows but I need a break :P
http://codepen.io/CrocoDillon/pen/xmBuA
@CrocoDillon Dude, you're a rock star. Thank you. One question, how can I replace your arrows with my own?
Edit: Nevermind. I removed the overriding backgrounds. How can I attribute you, URL + name or just name?
Hehe ^_^ I see you already figured that out.
Ermmm, I haven't thought about that. No attribution needed but if you insist just name will be fine since my website is just a placeholder right now :P
@CrocoDillon I tried implementing it live but it's not working for some reason.
http://chrisburton.me/dev
All right, sounds good.
Seems to be a problem with setting multiple id's on the
#ajaxdiv, there can be only one id for each element.I changed my mind, add www.crocodillon.com instead of my css-tricks profile, if that's cool with you :) I do plan to have content soon anyway.
@CrocoDillon Ha, nice catch. Everything works like a charm. Thanks again.
Not a problem for the attribution. Updated.
You're welcome :) and thnx!
@CrocoDillon Sorry to bother you again, is there any way to stop the blocks from shifting when resizing the browser?
Click the right arrow once until you get to the numbers 4, 3 and 2. Now, resize the browser and you will see 4 leaves the area while 1 slips in.
site: http://chrisburton.me/dev
JS file: http://chrisburton.me/dev/assets/js/functions.js
I'm playing with the idea of using % as positioning and it seems to fix that problem, but it adds another. How to know what % to use?
left: -100%;translates to 985px, if I'd figure out where this number comes from I could write the code to calculate the exact % to use, instead of what I'm doing here http://codepen.io/CrocoDillon/pen/xmBuA , using multiples of -100%.@CrocoDillon Perhaps all three widths (320px * 3 = 960) and a margin of the arrow (320px * 3 + 25px = 985px)? Although, I'm not seeing anything rendering 985px. I wonder if wrapping it in another div might help.
Update: I don't want to jump the gun here but using percentages rather than pixels is working when I hard code it into Web Inspector.
For me it doesn't, if I use -100% on #ajax then there is a border visible that shouldn't be visible. Maybe just go with that for now and remove the border for nth-child(3n) again? Or hardcode the 985px in JS (which sucks), I've updated my pen for that. Still an unwanted border though on the 2nd page.
Darn. It doesn't work either. When the browser is resized and you click the arrow, it doesn't calculate correctly.
I'm puzzled, let me think about that for a while. Go with the first solution for now? Seems to be the best solution as long as users don't resize after scrolling...
@Crocodillon Yeah, I figured that was the best option for now. Take your time, much appreciated for the help.
At least I found out where the 985px comes from. jQuery's
.position().leftgets the position relative to first positioned ancestor (in this case.page-wrap) "Oops" :P That element has 25px padding. So the slider started at 25px relative to that element. Sliding it 100% (or 1010px) to the left made it 985px. At least this isn't a concern anymore, since we aren't setting or getting the#ajaxposition using that jQuery function. Using the function on the articles worked because#ajaxis their positioned ancestor.So multiples of -100% should work, except it doesn't because the total width of 3 articles is (or should be) 100%, adding borders makes it go over 100%. Using
box-sizing: border-box;fixes that. Updated pen: http://codepen.io/CrocoDillon/pen/xmBuACan probably cleanup the javascript alot now, a lot vars that aren't needed anymore. (Edit: done)
@Crocodillon That's actually weird because I was applying
box-sizing: border-box;if you take a look at my reset: http://chrisburton.me/dev/assets/styles/reset.cssBut it seems to work on localhost perfectly so maybe it was because I didn't declare it in CodePen?
I don't know, I only tested on CodePen, but yeah that's weird. Maybe what you had were just rounding errors? I did put a few extra decimals to
.article { width: 33.3333%; }, and any additional rounding errors get masked with@CrocoDillon Gotcha. Well, from what I can tell it does work now. Any minor issues I can fix with media queries, I think. Thanks again for taking the time to help me out with this!