How can I make my level menu scrollable vertically?
Here is some code that I use to scroll vertically, I've adapted it to fit your menu. It doesn't perfectly line up to all your items, but it'll give you somewhere to start. And it'll show you how to figure this out on your own.
EDIT: I've updated the code use these funds instead. Still declare your buttons the same way but call my createMenu func to actually create the menu. It is looped so it auto adjusts if you change the number of menu items. the only thing you have to be aware of is; if you add or remove buttons change the array at the top of createMenu accordingly. Also adjust the padding variable to how much vertical space you want between the items
func createMenu() {
let buttons = [levelButton1, levelButton2, levelButton3, levelButton4, levelButton5, levelButton6, levelButton7, levelButton8, levelButton9, levelButton10, levelButton11, levelButton12, levelButton13, levelButton14, levelButton15, levelButton16, levelButton17, levelButton18]
let padding: CGFloat = 400
let numberOfRows = CGFloat(buttons.count / 3)
scrollCell = SKSpriteNode(color: .blue, size: CGSize(width: 1024, height: levelButtonSize.height * numberOfRows + padding * numberOfRows))
scrollCell.position = CGPoint(x: 0 - self.size.width / 4, y: 0 - (scrollCell.size.height - self.size.height / 2))
scrollCell.anchorPoint = CGPoint.zero
scrollCell.zPosition = 0
self.addChild(scrollCell)
// let backgroundImage = SKSpriteNode(imageNamed: "bg")
// backgroundImage.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
// self.addChild(backgroundImage)
let column1PosX = scrollCell.size.width / 3 / 2
let column2PosX = scrollCell.size.width / 2
let column3PosX = scrollCell.size.width / 3 / 2 + scrollCell.size.width / 3 * 2
var colCount = 0
var rowCount = 0
for button in buttons {
var posX: CGFloat = column2PosX
if colCount == 0 {
posX = column1PosX
}
else if colCount == 2 {
posX = column3PosX
colCount = -1
}
let indexOffset = CGFloat(rowCount) * (levelButtonSize.height + padding)
let posY = scrollCell.size.height - levelButtonSize.height / 2 - (indexOffset + padding / 2)
button.position = CGPoint(x: posX, y: posY)
button.setScale(0.5)
button.zPosition = 10
scrollCell.addChild(button)
if colCount == -1 {
rowCount += 1
}
colCount += 1
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first as UITouch! {
self.scrollCell.removeAllActions()
initialTouch = touch.location(in: self.scene!.view)
moveAmtY = 0
initialPosition = self.scrollCell.position
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first as UITouch! {
let movingPoint: CGPoint = touch.location(in: self.scene!.view)
moveAmtY = movingPoint.y - initialTouch.y
scrollCell.position = CGPoint(x: initialPosition.x, y: initialPosition.y - moveAmtY)
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
checkForResettingSlider()
yMoveActions(moveTo: -moveAmtY)
}
func checkForResettingSlider() {
let topPos: CGFloat = scrollCell.size.height - self.size.height / 2
let bottomPos = 0 - (self.size.height / 2)
if scrollCell.position.y > bottomPos {
let move = SKAction.moveTo(y: bottomPos, duration: 0.3)
move.timingMode = .easeOut
scrollCell.run(move)
}
if scrollCell.position.y < -topPos {
let move = SKAction.moveTo(y: -topPos, duration: 0.3)
move.timingMode = .easeOut
scrollCell.run(move)
}
}
func yMoveActions(moveTo: CGFloat) {
let move = SKAction.moveBy(x: 0, y: (moveTo * 1.5), duration: 0.3)
move.timingMode = .easeOut
self.scrollCell.run(move, completion: { self.checkForResettingSlider() })
}
How to enable vertical scrolling on some levels in multi-level fly-out menu
If you don't want to use javascript to decide "which year the qarter/month belongs to", a quick fix would be to position the child elements of the overflowed container relative to the viewport (position:fixed;
): https://jsfiddle.net/69yLp2fa/16/
Edit
Or with absolute positioning, but the rule is not to use overflow
and position
on the same container. Create another container for the overflown element and move positioning there, so that the absolute positioned child will not be placed relative to the overflow ancestor:
https://jsfiddle.net/hg8rbksy/2/
How to make long Bootstrap dropdown menus vertically scrollable?
You can do this by specifying max-height
and overflow-y
on the dropdown:
.dropdown-menu{
max-height: 400px;
overflow-y: auto;
}
You can calculate the max-height in JS or use viewport units. For example, if you want your dropdown to fill the space up until the bottom of the page, you could use: max-height: calc(100vh - 50px)
, where 50px is the height of your header.
Note that in the above solution the list on the left will not be scrolled independently of the dropdown. Once you reach the end of the dropdown, it will continue scrolling the list.
To prevent this, make the panel overflow as well:
.panel.panel-primary{
max-height: 60vh;
overflow-y: auto;
}
Again, it depends on your use case on how to go about to calculate the max heights.
CSS Vertical menu-submenu with scroll
The problem is that you defined a height in your element that creates a vertical scrollbar, if you don't need to set a fixed height for your container, you could try this change.
.scrollbar{
width:250px;
min-height:300px; /* min-height instead of height */
background-color:lightgray;
margin-top:40px;
margin-left:40px;
/*overflow-y:scroll;/* /*comment this line */
float:left;
}
.content{
min-height:450px; /* min-height instead of height */
}
Example without scroll
http://jsfiddle.net/guilhermelucio/0Lxtmeyp/2/
Update:
Example with scroll
See an example in JsFiddle: http://jsfiddle.net/guilhermelucio/0Lxtmeyp/3/
Making a drop-down menu scrollable
Try this using css
like,
#topNav ul li ul{
max-height:250px;/* you can change as you need it */
overflow:auto;/* to get scroll */
}
Demo
Mobile slide menu scrollable
Fixed it myself:
overflow-y: scroll;
Related Topics
How to Animate Bordercolor Change in Swift
Nsurlerrordomain with Code=-1100
How Are Hash Collisions Handled
Swift Combine How to Skip an Event
Index Out of Range in Swift with Removeatindex
Why Can't I Mutate a Variable Initially Set to a Certain Parameter When the Func Was Called
Physics Detecting Collision Multiple Times
\N in the End of Line with Using Print
Google API - Invalid Credentials
How to Disable a Constraint Programmatically
Swift Struct Initialization, Making Another Struct Like String
How to Draw a Line Between Two Points in Scenekit
Hot to Decode JSON Data That Could and Array or a Single Element in Swift
How to Save the Attributed String (Text) into File (Swift, Cocoa)