Module:Sprite: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:
local cellHeight = sheetHeight / noOfColumns
local cellHeight = sheetHeight / noOfColumns
local outerSpan = mw.html.create('span')
local span = mw.html.create('span')
outerSpan
:css({
:css({
position = 'relative',
position = 'relative',
Line 20: Line 19:
['vertical-align'] = 'middle'
['vertical-align'] = 'middle'
})
})
return tostring(outerSpan)
:tag('span')
:css({
position = 'absolute'
})
:done()
return tostring(span)
end
end


return p
return p

Revision as of 08:24, 27 May 2022

Documentation for this module may be created at Module:Sprite/doc

local p = {}

p.main = function( frame )
	local ratio = tonumber(frame.args['ratio'])
	local sheetWidth = tonumber(frame.args['sheetWidth'])
	local sheetHeight = tonumber(frame.args['sheetHeight'])
	local noOfRows = tonumber(frame.args['noOfRows'])
	local noOfColumns = tonumber(frame.args['noOfColumns'])
	local cellWidth = sheetWidth / noOfRows
	local cellHeight = sheetHeight / noOfColumns
	
	local span = mw.html.create('span')
		:css({
			position = 'relative',
			height = tostring(cellHeight * ratio) .. 'px',
			width = tostring(cellWidth * ratio) .. 'px',
			overflow = 'hidden',
			display = 'inline-block',
			['vertical-align'] = 'middle'
		})
		:tag('span')
		:css({
			position = 'absolute'
		})
		:done()
	return tostring(span)
end

return p